douyun1546
douyun1546
2013-06-29 17:30

从表更新密码

已采纳

So i have a project, that have a simple login system. There is a "users" table, that have "username" and "password" ecnrypted with SHA1.

And i have a simple form, that will change the password of the account that is logged in. But it is not working. Here is what i got:

<?php
include('connect.php');
if(isset($_POST['change']))
{
$nova_password = $_POST["nova_password"];
session_start(); 
$utilizador = $_SESSION['username'];
    if (empty($nova_password)) {
    $nopassword = '<span  class="error">Insira uma nova password!</span></br>';
    echo $nopassword;
    }
    if(!empty($nova_password))
    {
    $query = mysql_query("update users set password=SHA1('$nova_password') where username='$utilizador'");
    $sucesso = '<span  class="yes">Password Alterada com Sucesso!</span>';
    echo $sucesso;
    }
} //END IF
?>

When i go to the page, it says:"A session had already been started - ignoring session_start()".

This error appear before i click the button.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • dsbfbz75185 dsbfbz75185 8年前

    You have already started a session? Try removing session_start(); under $nova_password

    Edit: Do this

    $query = mysql_query("update users set password=SHA1('$nova_password') where username='$utilizador'");
    
    // Destroy session and send them to login form
    session_destroy();
    header("Location: http://yourdomain.com/login.php");
    exit();
    

    But If you'd like to echo a message first you could use header( "refresh:seconds;url=wherever.php" );. But yes make sure no headers have been sent yet. Else you could use <meta http-equiv="refresh" content="seconds;url=url">

    Or you could turn on output buffering ob_start(). Then it don't matter.

    点赞 评论 复制链接分享
  • doureng5668 doureng5668 8年前

    Substitute session_start() line with this:

    if(!isset($_SESSION))
        session_start();
    
    点赞 评论 复制链接分享

相关推荐