我不知道哪里出错了。当我勾选记住我复选框页面没有转到用户区域页面并且似乎 cookie 无法正常工作当我只登录而不勾选记住我复选框时它可以工作
<?PHP
session_start();
$connect=mysql_connect("localhost", "root", "");
mysql_select_db("phplogin", $connect);
function loggedin(){
if(isset($_SESSION['email']) || isset($_COOKIE['username'])){
$loggedin=TRUE;
return $loggedin;
}
}
if(loggedin()){
header("Location:userarea.php");}
if(isset($_POST['login'])){
$email=$_POST['email'];
$password=$_POST['password'];
$rememberme=$_POST['rememberme'];
if($email && $password){
$login=mysql_query("SELECT * FROM users WHERE email='$email'");
while($row=mysql_fetch_assoc($login)){
$db_email=$row['email'];
$db_password=$row['password'];
$db_firstname=$row['firstname'];
$db_lastname=$row['lastname'];
if($password==$db_password){$log=TRUE;}
else{$log=FALSE;}
}
if($log==TRUE){
if($rememberme=="on"){
setcookie("email", $email, time()+7200);
}
else if($rememberme==""){
$_SESSION['email']=$email;
header("Location:userarea.php");
}
}
else{die("Wrong email or password");}
}
}
?>
<html>
<form action="index.php" method="POST">
<input type="text" name="email" value="" placeholder="email" /><br/>
<input type="password" name="password" value="" placeholder="password"/><br/>
<input type="checkbox" name="rememberme"> Remember me | <a href="register.php">Register?</a><br/>
<input type="submit" name="login" value="Login" />
</form>
</html>