Help fixing this redirecting problem
<p>On index.php, I want to redirect users that are logged in to home.php ana also check if a cookie is set and redirect them if the cookie is storing the correct info. But the problem is, if a user saved a cookie and wants to logout and go to the index page, he can't since the index page will re-check his saved cookie and re-sign him in. Please help:</p>

<pre><code>&lt;?php

include("checkcook.php");

function redirect() {
    header('location:home.php');
    die();
}

session_start();

if((isset($_COOKIE["jmuser"])) &amp;&amp; (isset($_COOKIE["jmpass"]))){
    checkCookie($_COOKIE["jmuser"], $_COOKIE["jmpass"]);
    } 

if(isset($_SESSION['username'])){
            redirect();
        }
?&gt;
</code></pre>

<p>Oh and here is checkcook.php</p>

<pre><code>&lt;?php
    function checkCookie($username, $password){

        $conn=mysql_connect("localhost", "***", "***") or die(mysql_error());
        mysql_select_db('jmtdy', $conn) or die(mysql_error());

        $result=mysql_query("select * from users where username = '$username'");
        if($result != false){

            $username=mysql_real_escape_string($username);
        $password=mysql_real_escape_string($password);

            $dbArray=mysql_fetch_array($result);
            $dbArray['password']=mysql_real_escape_string($dbArray['password']);
            $dbArray['username']=mysql_real_escape_string($dbArray['username']);

        if(($dbArray['password'] != $password ) || ($dbArray['username'] != $username) || ($dbArray['active'] != '1')){
                setcookie("jmuser","",time()-3600);
                setcookie("jmpass","",time()-3600);
                session_unset($_SESSION['username']);
                session_unset($_SESSION['password']);
                return;
                }
                $_SESSION['username']=$username;
                return true;
               }

            else{

                setcookie("jmuser","",time()-3600);
                setcookie("jmpass","",time()-3600);
                session_unset($_SESSION['username']);
                return;
            }
        }

?&gt;          
</code></pre>

<p>and this is my logout code. But if I destroy the cookie, then the user would need to sign in every time he/she accesses the website? I don't want that.</p>

<pre><code>&lt;?php

function redirect() {
    header('location:index.php');
    die();
} 
session_start();
session_destroy();
redirect();

?&gt;
</code></pre>
