function isLogin(){
global $conn;
if(isset($_COOKIE["username"]) and isset($_COOKIE["password"])){
$rs = $conn->Execute("select id from members where username = '".$_COOKIE["username"]."' and password = '".$_COOKIE["password"]."'");
if($rs->RecordCount()<=0){
echo "<script>
alert('请登录.');
window.location.href='16_4.php';
</script>";
}
}
}
这是我网页的公共php文件中的定义的一个判定登录的函数。用户访问我的网站时,由于新学php web开发,我自己认为这个函数应该是在服务器上运行的。但是isset()函数中的$_cookie[" "]函数是对浏览器中的cookie的操作,难道这个函数是在服务器(我的电脑)上运行,但是调用的却是浏览器(用户电脑上)中的cookie执行的? 求大虾指导下谢谢!还有就是这个if(isset($_COOKIE["username"]) and isset($_COOKIE["password"])){
$rs = $conn->Execute("select id from members where username = '".$_COOKIE["username"]."' and password = '".$_COOKIE["password"]."'");
if($rs->RecordCount()<=0){
echo "<script>
alert('请登录.');
window.location.href='16_4.php';
</script>";
}
}
语句如果判定条件为假,那么它就什么都不做...这好像就没有达到判定登录的意义...不知道怎么才能做出一个比较友好的操作。也请大虾们帮帮给出点意见!....小弟我再次感谢!

解决方案 »

  1.   

    用户向服务器请求页面的时候,会在HTTP header中将cookie发送给服务器的。你用firefox抓个HTTP包就看到了。$_COOKIE["username"]都不存在,当然就是没有登录了,这个有什么疑问?
      

  2.   

    说错了,使用firebug在firefox上抓个包
      

  3.   

    在浏览器发起 http 连接后,会将 cookie 发送到服务器端。
    $_COOKIE 只是客户端 cookie 的一个副本