Young_Lady 2019-11-09 16:57 采纳率: 0%
浏览 622

各位大佬们,为什么PHP新闻发布系统中已经注册好的用户无法登录,总是显示密码错误,但是数据库有字段存在。。。

图片说明图片说明图片说明图片说明
以下是login_users_process.php的代码:
<?php
session_start();
include_once("functions/database.php");
$name = $_POST["name"];
if($_POST["checknum"] != $_SESSION["checknum"]){
header("Location:index_users.php?login_message=checknum_error");
return;
}
if(isset($_COOKIE["password"])){
$first_password = $_COOKIE["password"];
}else{
$first_password = md5($_POST["password"]);
}
if(empty($_POST["expire"])){
setcookie("name",$name,time()-1);
setcookie("password",$first_password,time()-1);
}
$password = md5($first_password);
$sql = "select * from users where name='$name' and password ='$password'";
get_connection();
$result_set = mysql_query($sql);
if(mysql_num_rows($result_set)>0){
if(isset($_POST["expire"])){
$expire = time()+intval($_POST["expire"]);
setcookie("name",$name,$expire);
setcookie("password",$first_password,$expire);
}

$users = mysql_fetch_array($result_set);
$_SESSION['user_id'] = $users['user_id'];
$_SESSION['name'] = $users['name'];
header("Location:index_users.php?login_message=password_right");
}else{
header("Location:index_users.php?login_message=password_error");
}
close_connection();
?>

以下是login_users.php 的代码
<?php
session_start();
include_once("functions/database.php");
include_once("functions/is_login.php");
if(isset($_GET["login_message"])){
if($_GET["login_message"]=="checknum_error"){
echo "验证码错误,重新登录!
";
}else if($_GET["login_message"]=="password_error"){
echo "密码错误,重新登录!
";
}else if($_GET["login_message"]=="password_right"){
echo "登录成功!
";
}
}
if(is_login()){
echo "欢迎".$_SESSION['name']."访问系统!
";
echo "注销";
return;
}
$name = "";
if(isset($_COOKIE["name"])){
$name = $_COOKIE["name"];
}
$password = "";
if(isset($_COOKIE["password"])){
$password = $_COOKIE["password"];
}
?>

用户名:
密 码 :
验证码:<?php $checknum = ""; $checknum .= mt_rand(0,9); $checknum .= mt_rand(0,9); $checknum .= mt_rand(0,9); $checknum .= mt_rand(0,9); $_SESSION['checknum'] = $checknum; echo $checknum;?>
Cookie保存1小时
  • 写回答

3条回答 默认 最新

  • threenewbee 2019-11-10 00:09
    关注

    $password = md5($first_password);
    你的密码是明文存放在数据库里的
    可你判断的时候做了一个md5
    两者不一致。

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮