PHP remember me, COOKIE
<p>I don't know where went wrong.
When I tick the remember me checkbox
The page didn't go to userarea page and seems like cookie didn't work as well
It works when I just login without tick the remember me checkbox</p>

<pre><code>&lt;?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 &amp;&amp; $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");}
    }
}
?&gt;

&lt;html&gt;
    &lt;form action="index.php" method="POST"&gt;
        &lt;input type="text" name="email" value="" placeholder="email" /&gt;&lt;br/&gt;
        &lt;input type="password" name="password" value="" placeholder="password"/&gt;&lt;br/&gt;

        &lt;input type="checkbox" name="rememberme"&gt; Remember me | &lt;a href="register.php"&gt;Register?&lt;/a&gt;&lt;br/&gt;
         &lt;input type="submit" name="login" value="Login" /&gt;
     &lt;/form&gt;
&lt;/html&gt;
</code></pre>
