<?
$pt_user_name=$_COOKIE['pt_user_name'];
if ($pt_user_name==''){
echo 'document.writeln("欢迎您的到来^0^ <a href=\"/User/Regters.aspx\">还没注册?</a>┊<a href=\"/User/ForgetPass.aspx\">忘记密码!</a>&nbsp;&nbsp;帐号&nbsp;<input name=\"username\" id=\"username\" size=\"10\" type=\"text\" class=\"inputout\" />&nbsp;密码&nbsp;<input name=\"password\" id=\"password\" type=\"password\" size=\"10\" class=\"inputout\"  />&nbsp;&nbsp;<select name=\"CookieTime\" hidefocus ><option value=\"1\" selected=\"true\">保存一天</option><option value=\"30\">保存一月</option><option value=\"365\">保存一年</option></select>&nbsp;&nbsp;<input name=\"UserLogin\" type=\"submit\" value=\"会员登陆\" style=\"padding-top:2px;margin-top:2px;\">");';
}else{
$pt_user_data=$_SERVER['DOCUMENT_ROOT'].'/user/data/'.$pt_user_name.'.pt';
if(file_exists($pt_user_data)){ include_once $pt_user_data;}
echo 'document.writeln("欢迎 <font color=red><b>'.$busername.'</b></font> 回来^0^ <a href=\"/User/index.aspx\">个人书屋</a> ┊ <a href=\"/User/User_Booklist.aspx\">藏书架</a> ┊ <a href=\"/User/edit.aspx\">修改资料</a> ┊ <a href=\"/User/logout.aspx\">退出</a>");';
}
?>这个是我的登录代码
在页面中用js调用 调用代码是<script src="http://localhost/templets/menulogin.php"></script>
进行验证的代码是if ($username==$login_check_username && $userpass==md5($login_check_userpass)){
setcookie("pt_user_name",$username,$time,"/");
echo "<script>location.href='$comeurl';</script>";exit;
}
我在a页面登陆后,经过b判断,然后重新返回a页面,但是显示还是未登录,不过刷新一下就是登陆状态了
退出也是 
这个是什么原因呢?

解决方案 »

  1.   

    呃 aspx只是后缀 内容还是php的
      

  2.   

    echo "<script>location.href='$comeurl';</script>";exit;$comeurl是来路url
    返回的是来路url
      

  3.   

    设置 cookie 后,cookie 还没有从服务器返回浏览器 所以必须刷新才可以.
      

  4.   

    设置COOKIE必须刷新后才能显示,基础!
      

  5.   

    是php的一个bug吧,登录后自己设定刷新一次就OK了。
      

  6.   

    COOKIE是保存在客户端的,要访问该页面后,才会在客户端保存了相应的COOKIE,之后才可以调用
      

  7.   

    把这echo "<script>location.href='$comeurl';</script>";exit;改成header('Location:'.$comeurl);exit;
      

  8.   

    注意用header函数之前不能有内容输出
      

  9.   


    兄弟我看你先把php的基础先学好吧~~  
      

  10.   

    我做了实验不存在这个问题啊
    你直接在URL里访问http://localhost/templets/menulogin.php呢