求助:登陆有效性的验证的问题(关于session)

xylegend 2004-03-16 09:27:40
我做了一个验证系统,当用户已经注册了bm_id后,就可以输入ID和密码登陆某指定的页面。为了验证,我们不允许未经登陆的id打开该页面,于是在该页面加入session的验证。比如我们要验证main.php页面,就在该页面代码里边加入:
<?php
session_start();
if(!isset($_SESSION['bm_id']))
{
header("location:err.php");
exit();
}
?>
<html>…………………………</html>
但是为什么,我的id和密码都正确,但是每次都是err.php的出错页面
而不是目的页面main.php??
...全文
130 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
anybody999 2004-03-16
  • 打赏
  • 举报
回复
E文不太好,不知道说的对不对~你自己看一下原文 不要意思~~~-_-!!

PHP4.06的改进

Fixed memory fragmention problem which could lead to web server processes growing much more than they should. (Andi, Zend Engine)
Made $HTTP_SESSION_VARS['foo'] and $foo be references to the same value when register_globals is on. (Andrei)
Fixed disk_free_space() and disk_total_space() under FreeBSD. (Jon)
Fixed readfile/passthru losing resources during connection abort (Sascha)
.
.
.


anybody999 2004-03-16
  • 打赏
  • 举报
回复
对不起上面我有 句话说错了 !
在php版本4.06以前有个bug
register_globals 为 on 的时候
$HTTP_SESSION_VARS['bm_id'] 有时候会等价于$bm_id
xylegend 2004-03-16
  • 打赏
  • 举报
回复
if(!session_is_registered($_SESSION['bm_id']))
这样看看
------------------------
也不行……
xylegend 2004-03-16
  • 打赏
  • 举报
回复
我的是php-4.3.4的,不管register_globals是否已经打开
我都可以使用$HTTP_SESSION_VARS或者$_SESSION来取得变量值啊
况且还是打开的,真的郁闷极了,几天前还好好的
只是离开几天,现在要上交论文程序了,就麻烦来了
我再次声明,代码是没有改的,几天前还好好的
现在突然之间为何就获取不到session了呢!!!
anybody999 2004-03-16
  • 打赏
  • 举报
回复
if(!session_is_registered($_SESSION['bm_id']))
这样看看

xylegend 2004-03-16
  • 打赏
  • 举报
回复
感觉上session真的好像没有注册到,问题何在呢?
anybody999 2004-03-16
  • 打赏
  • 举报
回复
看看你的php版本是不是>=4.06的
如果是:
那么register_globals 为 on 的时候
$HTTP_SESSION_VARS['bm_id'] 才等价于$bm_id

现在的问题是:你的session一定没有注册成功!
xylegend 2004-03-16
  • 打赏
  • 举报
回复
to bonniewater(陪你去看海) 朋友
我原本就好好的,根本没有动过它啊,session应该没有问题吧……
以前用的好好的,代码没有更改,只是离开了几天而已……郁闷!
anybody999 2004-03-16
  • 打赏
  • 举报
回复
看看你的php里的设置文件对session的设置是否正确
xylegend 2004-03-16
  • 打赏
  • 举报
回复
这样根本验证就完全一样啊,只是改了出错判断用js,看来也不会有什么效果的
bonniewater 2004-03-16
  • 打赏
  • 举报
回复
先Echo $_SESSION['bm_id'] 看看到底有没有注册上session
anybody999 2004-03-16
  • 打赏
  • 举报
回复
session没有注册成功
52juanjuan 2004-03-16
  • 打赏
  • 举报
回复
把你的代码改成:
<?php
session_start();
if(!session_is_registered($HTTP_SESSION_VARS['bm_id']))
{echo "<script>alert(You must login first');location:er.php;</script>";
exit();
}
?>
不知道可以不可以,我没有试过,但我以前是这样做的比如没有成功登录就返回原来页面就是用

<?php
session_start();
if(!session_is_registered($HTTP_SESSION_VARS['bm_id']))
{echo "<script>alert(You must login first');history.back();</script>";
exit();
}
?>
xylegend 2004-03-16
  • 打赏
  • 举报
回复
我将验证代码改为:
<?php
session_start();
if(!session_is_registered($HTTP_SESSION_VARS['bm_id']))
{
header("location:err.php");
exit();
}
?>
也不行,以前是好好的啊!!!??真是一头雾水,我将验证代码单独成一文件err.php
然后在要验证的页面最上端include进去的,就是不行……
anybody999 2004-03-16
  • 打赏
  • 举报
回复
晕,我在改程序的时候都已经2个人回答过了...............
anybody999 2004-03-16
  • 打赏
  • 举报
回复
我很奇怪你以前的程序是怎么运行起来的你的login_check.php好象并没有注册session啊,那么当然没有session值了,我把你的这个程序改了一下,你试试看
$query="select * from userinfo where bm_id = '$username'";
$result=mysql_query($query);
if(mysql_num_rows($result)=="")
{
echo"没有该用户!";
}
else if($_POST["password"]!=mysql_result($result,0,"bm_pass"))
{
echo"你的密码错误!";
}
else
{
session_start();
$_session['bm_id']=$_POST["username"];
$_session['bm_pass']=$_POST["password"];
if(!session_is_registered($_SESSION['bm_id']))
{
header("location:error.php");
exit();
}
else
Header("location:你的目标文件");
}
xylegend 2004-03-16
  • 打赏
  • 举报
回复
修改登陆认证代码后,问题得到解决,但费解的是
先前的为何不行了呢?
<?php
session_start();
if (isset($_POST['username']) && isset($_POST['password']))
{........
$_SESSION['bm_id'] =$_SESSION['username'];
$_SESSION['bm_pass'] =$_SESSION['bm_pass'];
...........}
xuancaoer 2004-03-16
  • 打赏
  • 举报
回复
你的login_check.php里边没有注册session吧
xylegend 2004-03-16
  • 打赏
  • 举报
回复
我将相关的程序段给出来,如下:
-----------------------------------------------------
表单提交:
<form name="form1" method="post" action="login_check.php">
<td height="120" align="center">
<table width="180" height="110" border="0" cellpadding="3" cellspacing="0" bgcolor="#CCCCCC" style="font-size: 12px;">
<tr>
<td width="60" height="20"> <div align="right">用户名:</div></td>
<td height="20" colspan="2"> <input name="username" type="text" id="username" size="12" maxlength="16">
</td>
</tr>
<tr>
<td width="60" height="20"> <div align="right">密码:</div></td>
<td height="20" colspan="2"> <input name="password" type="password" id="password" size="12" maxlength="20">
</td>
--------------------------------------------------------
//login_check.php
$query="select * from userinfo where bm_id = '$username' and bm_pass = '$password'";
$result=mysql_query($query);
isset($_POST['username'])) {
if(login($username,$password)) {
header("Location: main.php");
exit();
}else
echo "请输入正确的用户名和口令";
//bm_id和bm_pass是数据表里的字段,这段程序用来判断用户提交的用户名和密码是否正确
//如果正确就转到main.php页面

如下是main.php里边的验证代码:检测session是否已注册,未注册则error.php,否则就是main.php的内容
<?php
session_start();
if(!session_is_registered($_SESSION['bm_id']))
{
header("location:error.php");
exit();
}
?>
有什么问题呢???
xylegend 2004-03-16
  • 打赏
  • 举报
回复
Made $HTTP_SESSION_VARS['foo'] and $foo be references to the same value when register_globals is on.
这个不是bug啊,只是打开了全局变量而已,不过跟我的问题好像也没有多大关系
当register_globals 为on的时候,我可以在别的页面自动取得$bm_id
如果register_globals为off则必须$_SESSION['bm_id']或者$HTTP_SESSION_VARS['bm_id']
才能取得值,我现在费解的是我的逻辑判断都没有错啊,但就是不能达到目的

21,882

社区成员

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

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