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
    两者不一致。

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题