cookie checkbox glitch
<p>When I tick check box (cookie) and press log in
it didn't header to member page. It header to index page (current page).</p>

<p>but when I tick the check box (cookie) and press log again
it header to member page</p>

<p>anyone can help me where is the problem?</p>

<pre><code>&lt;?PHP
session_start();

function loggedin(){
    if(isset($_SESSION['log_email']) || isset($_COOKIE['log_email'])){
    $loggedin=TRUE;
    return $loggedin;   
    }
}

$log_email="";

if(loggedin()){
header("Location:member.php");}

if(isset($_POST['login'])){

    $log_email=strtolower($_POST['log_email']);
    $log_password=$_POST['log_password'];

    if(isset($_POST['cookie'])){
    $cookie=$_POST['cookie'];
    }


    if($log_email &amp;&amp; $log_password){
        $connect=mysql_connect("localhost", "root", "");
        $database=mysql_select_db("phplogin", $connect);

        $SQL=mysql_query("SELECT * FROM users WHERE email='$log_email'");
        $numrows=mysql_num_rows($SQL);

        if($numrows!=0){
            while($result=mysql_fetch_assoc($SQL)){
                $db_email=$result['email'];
                $db_password=$result['password'];
                $db_firstname=$result['firstname'];
                $db_lastname=$result['lastname'];
            }

            if($log_email==$db_email &amp;&amp; md5($log_password)==$db_password){      
                    if($cookie){
                        setcookie("log_email", $log_email, time()+7200);
                    }
                    else{
                    $_SESSION['log_email']=$log_email;
                    header("location:member.php");
                    exit();
                    }
            }
            else{echo"wrong username or password";}
        }
        else{echo "Can't find the user";}
    }
    else{echo "Please enter email or password";}
}


?&gt;




&lt;html&gt;
&lt;body&gt;
&lt;div id="container"&gt;
&lt;div id="logo"&gt;&lt;/div&gt;
    &lt;div id="search"&gt;&lt;/div&gt;
    &lt;div id="top_search"&gt;&lt;/div&gt;


    &lt;div id="login"&gt;
        &lt;form action="index.php" method="POST"&gt;
        &lt;table&gt;
            &lt;tr&gt;
                &lt;td&gt;&lt;lable id="td_1"&gt;Email&lt;/lable&gt;&lt;/td&gt;
                &lt;td&gt;&lt;lable id="td_1"&gt;Password&lt;/lable&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
                &lt;td&gt;&lt;input type="text" name="log_email" value="&lt;?PHP echo $log_email; ?&gt;" maxlength="50"/&gt;&lt;/td&gt;
                &lt;td&gt;&lt;input type="password" name="log_password" maxlength="25" /&gt;&lt;/td&gt;
                &lt;td&gt;&lt;input id="log_btn" type="submit" name="login" value="" /&gt;&lt;/td&gt;
            &lt;/tr&gt;
              &lt;tr&gt;
                &lt;td&gt;&lt;div id="td_2"&gt;&lt;input type="checkbox" name="cookie"/&gt;Remember me&lt;/div&gt;&lt;/td&gt;
                &lt;td&gt;&lt;div id=td_2&gt;&lt;a href="forgot_password.php"&gt;Forgot your password?&lt;/div&gt;&lt;/a&gt;&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
        &lt;/form&gt;
    &lt;/div&gt;   

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
