新手提问,请高手指教。php的登录验证问题

bumm 2005-04-18 09:14:55
我在登录窗口输入用户名和密码后,验证后跳转到第二个页面。可是关闭第二个页面后,再次登录时,只要密码正确(和第一次一致),不管用户名输入什么都能通过验证。代码如下,请高手指教。

------------------------------------------------------------------------------------------
<html>
<head>
<title>登陆</title>
</head>
<body>
<a href="shenqing.php">申请新用户<a>
<hr>
<?
@session_destroy();
@session_unregister("userid");
@session_unregister("password");
?>
<form action="panduan.php" method="post">
请输入用户名:
<input type="text" name="userid" >
<p>
请输入密码:
<input type="text" name="password">
<p>
<input type="submit" value="登陆">
</form>
</body>
</html>
------------------------------------------------------------------------------------------
<?
//echo "$userid";
if(!($userid))
{
echo "请填写用户id";
}
$connection=mysql_connect("localhost","root");
mysql_select_db("kaoqin");
$query="select * from userdata where userid='$userid' ";
$result=mysql_query($query,$connection);
mysql_close($connection);
while($row=mysql_fetch_array($result))
{
if($password==$row[password])
{
setcookie("userid",$userid,time()+3600);
include("kaoqin_main.php");
}
else
{
echo "用户id/密码不正确,请重新操作";
}
}
?>
...全文
110 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
bumm 2005-04-18
  • 打赏
  • 举报
回复
我在登录窗口输入用户名和密码后,验证后跳转到第二个页面。可是关闭第二个页面后,再次登录时,只要密码正确(和第一次一致),不管用户名输入什么都能通过验证。
bumm 2005-04-18
  • 打赏
  • 举报
回复
怎么还是不行阿?大师们
bumm 2005-04-18
  • 打赏
  • 举报
回复
就是请输入用户名后面我什么都不写,他也默认是第一次登陆的
zhutimy 2005-04-18
  • 打赏
  • 举报
回复
建议使用$_POST["password"]等类似的变量
coolstr 2005-04-18
  • 打赏
  • 举报
回复
应该是和session同名所致,
解决办法:
请输入密码:
<input type="text" name="password">

改为:
请输入密码:
<input type="text" name="passwordAAA">

或者把session的password改成不一样就没有问题了。
bumm 2005-04-18
  • 打赏
  • 举报
回复
自己先顶一下
slowslow 2005-04-18
  • 打赏
  • 举报
回复
这样写不好吧。那样你的密码都看到了。

<input type="password" name="password">


<?
@session_destroy();
@session_unregister("userid");
@session_unregister("password");
?>去了。因为你的session里的用户名起作用。每次关闭的时候最好把 session 杀掉
最好用脚本再写个判断用户名和密码的条件

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧