douyun1546 2013-06-29 17:30
浏览 26
已采纳

从表更新密码

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 2013-06-29 17:34
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘