PHP会员登录成功后不能跳转

做了验证代码的页面check.php代码如下
<? require "cover.php";
session_start();
$username=$_POST["username"];
$password=$_POST["password"];
$sql = "select * from user where u_name='$username' and u_flag!=0";
$m = mysql_query($sql);

while($r=mysql_fetch_array($m)){
$upass=$r["u_pass"];
$uuser=$r["u_name"];
$uid=$r["u_id"];
}
session_register("ses_uid");
session_register("ses_uuser");
session_register("ses_msuccessful");
$ses_msuccessful=0;

if($password==$upass&&$password!="")
{
$ses_msuccessful=1;
$ses_uid=$uid;
$ses_uuser=$uuser;

// echo "asdfsdfsdf";
header("location:index.php");
}
else{ echo '用户或密码错误<a href="index.php"><返回></a>';

}

?>
可是在登录成功的时候不能跳转到有sessin会员名的页面,麻烦高手帮忙看看啊
这是登录界面的代码top.php以嵌入的形式茶在首页index.php中
<? if($_SESSION["ses_msuccessful"]==0) {?>
<table border="0" bgcolor="f1f1f1">
<form action="check.php" method="post" name="n" id="n">
<tr><td width="70" align="center">用户名:</td>
<td width="178">
<input name="username" type="text" id="username" size="20" maxlength="10" /> </td>
<td width="76" align="center">密码:</td>
<td width="176"><label>
<input name="password" type="password" id="password" size="20" />
</label></td>
<td width="199"><label>
<input type="submit" name="Submit" value="登陆" />
<input type="button" name="Submit23" value="注册" onclick="location.href='zhuche.php';"/>
</label></td>
</tr></form>
</table>
<? } if($_SESSION["ses_msuccessful"]==1) { ?>
<table border="0" bgcolor="f1f1f1">
<tr><td width="218" align="left">你好:<? echo $_SESSION["ses_uuser"];?></td>
<td width="78"> <a href="loginout.php">退出</a></td>
3楼的大神,我改了运行的时候就停留在check.php页面了都不会跳回首页了

其实在很久以前,PHP已经不再使用session_register()函数来注册session变量了,而是直接使用$_SESSION["var"]="value";了,你不会告诉我,你的PHP低于4.0版本吧。你把这几行
session_register("ses_uid");
session_register("ses_uuser");
session_register("ses_msuccessful");
$ses_msuccessful=0;
去掉,而下面的判断语句
$ses_msuccessful=1;
$ses_uid=$uid;
$ses_uuser=$uuser;
直接用$_SESSION['ses_msuccessful']=1来完成

其实你在index.php页面中也是这样做的,看你的代码
if($_SESSION["ses_msuccessful"]==1)

这样岂不是更简单,也更直观,对你的代码来说,也更简单!登录只是一个简单的PHP应用,你的header()没有问题,你改完后再试一下。

----我也补充一下,你在SESSION_START这前的cover.php页面有没有echo之类的输出语句啊?抛去我原来位置楼下所说的安全性不谈, 我刚才在我的电脑上用你的语句试了一下,主要是这段
if($password==$upass&&$password!="")
{
$ses_msuccessful=1;
$ses_uid=$uid;
$ses_uuser=$uuser;

// echo "asdfsdfsdf";
header("location:index.php");
}
header是没有问题的,如果没有跳转,我只能怀疑if语句了。这样交流实在有些不实时,也麻烦,有可能HI我吧
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-08-04
while($r=mysql_fetch_array($m)){
$upass=$r["u_pass"];
$uuser=$r["u_name"];
$uid=$r["u_id"];
}

直接写成:
$r=mysql_fetch_array($m);
$upass=$r["u_pass"];
$uuser=$r["u_name"];
$uid=$r["u_id"];
不要while,你试试
第2个回答  2010-08-04
header("location:index.php");
登陆成功跳转到这个页面?
第3个回答  2010-08-09
把php文件简化成下面的代码,是可以运行的。所以header语句是没有问题的。
可能真的是判断语句那里出问题,自己先一段一段代码试着排除一下。另外提一下,确实该升级php版本了,一些老的书里面的例子还是用session_register,不过一般现在不用了,直接赋值。
<?
session_start();
$username=a;
$password=b;
$_SESSION['ses_uid']=1;
$_SESSION['ses_uuser']=$username;
$_SESSION['ses_msuccessful']=$password;
header("location:index.php");
?>
第4个回答  2010-08-04
header不太好用的,最好用Javascript
echo "<script. language='javascript'>";
echo " location='网址';";
echo "</script>";
第5个回答  2010-08-05
你这个是php几啊,session还用注册?直接赋值就可以。。。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网