No Session after logging in
<p>I have a strange issue. I've create a login page in PHP that works fine. I've decided to destroy any session when a user hits the login page. But, by doing this the user is never logged in. I can't see the issue.</p>

<p>Login page</p>

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

// Destroy any active session
session_destroy();

// Regenerate Session ID
session_regenerate_id(true);

if($_SERVER['REQUEST_METHOD'] == 'POST') {
    $username = $_POST['username'];
    $password = md5($_POST['password']);

    if(strlen($username) &gt; 12) {
        header('Location: index.php');
    }

    try {
        $dbh = new PDO('mysql:dbname=addcovers;host=127.0.0.1', 'root', '');
        $sth = $dbh-&gt;prepare('SELECT display_name FROM users WHERE username = :username &amp;&amp; password = :password');
        $sth-&gt;bindParam(':username', $username, PDO::PARAM_STR, 12);
        $sth-&gt;bindParam(':password', $password, PDO::PARAM_STR, 32);
        $sth-&gt;execute();
        $result = $sth-&gt;fetch(PDO::FETCH_OBJ);

        if($result) {
            $_SESSION['logged_in'] = true;
            $_SESSION['user'] = $result-&gt;display_name;
            header('Location: index.php');
        }
    } catch (PDOException $e) {
        // DEBUG: echo 'Connection failed: ' . $e-&gt;getMessage();
    }

}
?&gt;
&lt;!DOCTYLE html&gt;
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;&lt;/title&gt;

    &lt;link rel="stylesheet" href="css/reset.css" type="text/css" media="all"&gt;
    &lt;link rel="stylesheet" href="css/base.css" type="text/css" media="all"&gt;
&lt;/head&gt;

&lt;body id="admin-login"&gt;
    &lt;form action="login.php" method="POST"&gt;
        &lt;fieldset&gt;
            &lt;div&gt;&lt;label for="username"&gt;Username&lt;/label&gt;&lt;input type="text" name="username" maxlength="12"&gt;&lt;/div&gt;
            &lt;div&gt;&lt;label for="password"&gt;Password&lt;/label&gt;&lt;input type="password" name="password"&gt;&lt;/div&gt;
            &lt;button type="submit"&gt;Admin Login&lt;/button&gt;
        &lt;/fieldset&gt;
    &lt;/form&gt;
&lt;/body&gt;
</code></pre>

<p></p>

<p>Admin Page</p>

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

if(!isset($_SESSION['logged_in'])) header('Location: login.php');

echo 'Welcome ' . $_SESSION['user'];

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

<p>If I remove the <code>session_destroy</code> from the login page it works fine. Currently though the user keeps hitting the login page even if the credentials are correct.</p>
