Keeping a user logged in while they browse website
<p>When a user logs into my website login.php checks if they have the correct username password or if they are an administrator:</p>

<pre><code>session_start ();

$username = '';
$password = '';
$dbusername = '';
$dbpassword = '';
if (isset($_POST['Email']) &amp;&amp; isset($_POST['Password']))
{
    $username = $_POST['Email'];
    $password = md5($_POST['Password']);



$query = mysql_query("SELECT * FROM member WHERE Email ='$username' AND Password='$password'");


$numrow = mysql_num_rows ($query);
// user login
if ($numrow!=0)
{
    while ($row = mysql_fetch_assoc($query))
    {
        $dbusername = $row['Email'];
        $dbpassword = $row['Password'];
    }

    //Check to see if they match
    if ($username==$dbusername&amp;&amp;$password==$dbpassword)
    {
        header("Location: member.php");
        $_SESSION ['Email']=$username;

    }
    }
    else 
    {
        // admin login
        $query2 = mysql_query("SELECT * FROM admin WHERE Email ='$username' AND Password ='$password'");
        $numrow2 = mysql_num_rows ($query2);
        if ($numrow2!=0)
        {
            while ($row = mysql_fetch_assoc($query2))
            {
                $dbusername = $row['Email'];
                $dbpassword = $row['Password'];
            }

            //Check to see if they match
          if ($username==$dbusername&amp;&amp;$password==$dbpassword)
            {
                header("Location: admin.php");
                $_SESSION ['Email']=$username;
            }
            else{

                echo "Incorrect password";
            }

        }
            else{
        if ($username!=$dbusername&amp;&amp;$password!=$dbpassword)
        {die("That user does not exist!");
        }
        }
    }
}
</code></pre>

<p>They are redirected to member.php (relevant code below)</p>

<pre><code>session_start ();

     If (logged_in() === true)//Email 
           echo "Welcome, ".$_SESSION['Email']. "!&lt;br&gt;&lt;ahref='logout.php'&gt;Logout&lt;/a&gt;";
     else
    die ("You must be logged in");
</code></pre>

<p>This all works fine, the user is logged in and their username displays on the top of the page, but if the user goes back to the homepage or any other page on the website they are no longer logged in. Totally confused on how to do this, any help would be great. </p>
