做了验证代码的页面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页面了都不会跳回首页了
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我吧
$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,你试试
登陆成功跳转到这个页面?
可能真的是判断语句那里出问题,自己先一段一段代码试着排除一下。另外提一下,确实该升级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");
?>
echo "<script. language='javascript'>";
echo " location='网址';";
echo "</script>";