我将验证代码改为:
<?php
session_start();
if(!session_is_registered($HTTP_SESSION_VARS['bm_id']))
{
header("location:err.php");
exit();
}
?>
也不行,以前是好好的啊!!!??真是一头雾水,我将验证代码单独成一文件err.php
然后在要验证的页面最上端include进去的,就是不行……
<?php
session_start();
if(!session_is_registered($HTTP_SESSION_VARS['bm_id']))
{
header("location:err.php");
exit();
}
?>
也不行,以前是好好的啊!!!??真是一头雾水,我将验证代码单独成一文件err.php
然后在要验证的页面最上端include进去的,就是不行……
<?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();
}
?>
我原本就好好的,根本没有动过它啊,session应该没有问题吧……
以前用的好好的,代码没有更改,只是离开了几天而已……郁闷!
如果是:
那么register_globals 为 on 的时候
$HTTP_SESSION_VARS['bm_id'] 才等价于$bm_id现在的问题是:你的session一定没有注册成功!
这样看看
我都可以使用$HTTP_SESSION_VARS或者$_SESSION来取得变量值啊
况且还是打开的,真的郁闷极了,几天前还好好的
只是离开几天,现在要上交论文程序了,就麻烦来了
我再次声明,代码是没有改的,几天前还好好的
现在突然之间为何就获取不到session了呢!!!
这样看看
------------------------
也不行……
在php版本4.06以前有个bug
register_globals 为 on 的时候
$HTTP_SESSION_VARS['bm_id'] 有时候会等价于$bm_id
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)
.
.
.
这个不是bug啊,只是打开了全局变量而已,不过跟我的问题好像也没有多大关系
当register_globals 为on的时候,我可以在别的页面自动取得$bm_id
如果register_globals为off则必须$_SESSION['bm_id']或者$HTTP_SESSION_VARS['bm_id']
才能取得值,我现在费解的是我的逻辑判断都没有错啊,但就是不能达到目的
-----------------------------------------------------
表单提交:
<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();
}
?>
有什么问题呢???
先前的为何不行了呢?
<?php
session_start();
if (isset($_POST['username']) && isset($_POST['password']))
{........
$_SESSION['bm_id'] =$_SESSION['username'];
$_SESSION['bm_pass'] =$_SESSION['bm_pass'];
...........}
$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:你的目标文件");
}