0

我有这段代码,但是当我尝试加载页面时它是空白的:(我用 USERCOOKIEID 和 PASSCOOKIEID 替换了 cookie 的实际名称,并删除了用户登录时发生的代码)

if(isset($_COOKIE['USERCOOKIEID'])) { 
$user = $_COOKIE['USERCOOKIEID']; 
$pass = $_COOKIE['PASSCOOKIEID'];
$check = mysql_query("SELECT * FROM users WHERE username = '$user'")or die();
while($info = mysql_fetch_array($check)) {
    if ($pass != $info['password']) {           
    }else{
    //This is were the code goes for a user that is signed on
    }
}

}else{//what happens if they don't have the cookie
header("Location: login.php");

}

谢谢

4

1 回答 1

1

应该看起来像

if(isset($_COOKIE['USERCOOKIEID']))
{ 
    $user = $_COOKIE['USERCOOKIEID']; 
    $pass = $_COOKIE['PASSCOOKIEID'];
    $check = mysql_query("SELECT * FROM `users` WHERE `username`='$user'") or die();
    if (mysql_result($check, 0, 'passwordcolnum') == $pass) {
    } else {
        //This is were the code goes for a user that is signed on
    }
} else { //what happens if they don't have the cookie
    header("Location: login.php");
}

也,而不是mysql_fetch_array,你为什么不使用mysql_result肯定只有一条记录

于 2012-04-06T22:04:33.847 回答