I have to login twice
<p>For some reason the login to my site has to be done two times in order to work. If anyone has any idea why I appreciate it.</p>

<p>Here is the code I have for the authorization:</p>

<pre><code>&lt;?php
session_start();
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
require_once(SITE_ROOT.'includes/exceptions.php');
require_once(SITE_ROOT.'data/model.php');

/*
 * The purpose of this class is to manage
 * access to the application, making sure the
 * users are logged in before they can access
 * certain features
 */

class Auth extends Model
{
    function isUserLoggedIn()
    {
        /*
         *  Check for the user_id in $_SESSION
         * and see if it's the database. Return
         * true or false
         *
         */

        if(isset($_SESSION['user']))
        {
            return true;
        }
        else
        {
            return false;
        }

    }

    static function redirectToLogin()
    {
        header("location: http://". DOMAIN .APP_DIR . "index.php?action=login");
    }

    static function redirectToMain()
    {
        header("location: http://". DOMAIN . APP_DIR . "index.php?action=main");
    }

    static function login($user)
    {
        /*
         * Authenticate the user passing to the function
         * a instance of the User object
         */

        try
        {
            $db = parent::getConnection();
            $pass = $user-&gt;getPassword();
            $query = "select username, password from users where username = '".$user-&gt;getUsername()."' and password = '".$user-&gt;getPassword()."'";
            $results = $db-&gt;query($query);             

            if(empty($results)) {
                throw new Exception('There was a problem logging you in', EX_LOGIN_ERROR);
            }            

            $row = $results-&gt;fetch_assoc();           

            $user = $row['username'];
            $_SESSION['user'] = $user;

        }
        catch(Exception $e){
            throw $e;
        }
    }

    static function logout()
    {
        $old_user = $_SESSION['user'];
        unset($_SESSION['user']);
        session_destroy();
    }

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

<p>Thx</p>
