这两种登陆验证方法错哪了
Jun 13, 2016 am 10:15 AM
header
location
mysql
quot
这两种登陆验证方法哪里错了
第一种:
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $id=$_POST['id'];$password=$_POST['password']; $conn=mysql_connect("localhost","root","root"); if (!$conn){ die("连接失败:".mysql_errno()); } mysql_select_db("emp",$conn) or die(mysql_errno()); mysql_query("set names utf8")or die(mysql_errno());$sql = "select count(id) from admin where id='".$id."' and password='".md5($password)."'";$res = mysql_query($sql,$conn);$num = mysql_num_rows($res);if($num){ header("location:empManage.php"); exit();}else{ header("location:login.php?errno=1"); exit();}mysql_free_result($res);mysql_close($conn); ?>
登录后复制
此方法无论密码是否和数据库匹配都可以登陆
方法二:
- PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php $id=$_POST['id'];$password=$_POST['password']; $conn=mysql_connect("localhost","root","root"); if (!$conn){ die("连接失败:".mysql_errno()); } mysql_select_db("emp",$conn) or die(mysql_errno()); mysql_query("set names utf8")or die(mysql_errno()); $sql="select password from admin where id=$id"; $res=mysql_query($sql,$conn); if ($row=mysql_fetch_assoc($res)){ if ($row['password']==md5($password)){ header("location:empManage.php"); } }header("location:login.php?errno=1");mysql_free_result($res);mysql_close($conn);?>
登录后复制
此方法即使id和密码都正确都无法登陆
求高人指点,看看哪里错了导致无法登陆
------解决方案--------------------
忘了还有第二个了。
逻辑问题我想
if ($row=mysql_fetch_assoc($res)){
if ($row['password']==md5($password)){
header("location:empManage.php");
}
}
header("location:login.php?errno=1");
假设成功,先header("location:empManage.php"),可到最后仍然会执行header("location:login.php?errno=1")。 header()函数并不会执行后立即发送消息报头给浏览器,于是后面的覆盖了前面的。不过没测试过所以不敢打保票。
把逻辑理顺了看看
if ($row=mysql_fetch_assoc($res)){
if ($row['password']==md5($password)){
header("location:empManage.php");
exit();
}
}
header("location:login.php?errno=1");
------解决方案--------------------
$num = mysql_num_rows($res);
if($num){
header("location:empManage.php");
这里错了,应该是 读取count值,然后判断count是否为1则可
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章
击败分裂小说需要多长时间?
3 周前
By DDD
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌

热门文章
击败分裂小说需要多长时间?
3 周前
By DDD
仓库:如何复兴队友
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前
By 尊渡假赌尊渡假赌尊渡假赌
公众号网页更新缓存难题:如何避免版本更新后旧缓存影响用户体验?
3 周前
By 王林
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前
By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

如何修复 MySQL 8.4 上的 mysql_native_password 未加载错误
