重定向后丢失会话变量

This is my setup. The user can connect with facebook. I then use the facebook id to find the id in my user table. I want to add the facebook id and the user id from my table in the session. Then I redirect the user to the main page.

        /*
         * Leg til facebook id i session hvis bruker logger in/registrer seg med facebook
         */      
        $_SESSION['fb_id'] = $fb['id'];                     

        /*
         * Set user id
         */
        $_SESSION['id'] = $id; 

        /*
         * Auto log-out after 45 minutes
        */          
        $_SESSION['expires'] = time()+(45*60);

        /*
        * Log to db
        */  
        $this->log_login_attempt(true); 

        /*
        * Redirect user to game
        */           
        $host = $_SERVER["HTTP_HOST"]; 
        header("location: http://$host/homepage.php");  //@ redirect
        exit();

If I do a echo var_dump($_SESSION) before the redirect I get:

array(3) { ["fb_id"]=> string(9) "7683402XX" ["id"]=> int(12) ["expires"]=> int(1303482308) } 

So I redirect the user to homepage.php here I just enter:

error_reporting(E_ALL); 
ini_set("display_errors", true); 
require '../sys/core/errorhandler.php';
set_error_handler('my_error_handler');

$a = session_id();
if ($a == '') session_start();

echo var_dump($_SESSION); 
exit();     

This result in:

array(2) { ["id"]=> int(12) ["expires"]=> int(1303482647) } 

Somehow $_SESSION['fb_id'] disappeared? How can this happen?

Make sure you have session_start() at the very top of your script before you set $_SESSION['fb_id'] and so on. Without the session started, when you dump $_SESSION the values will be there, but as regular variables - they won't persist between page loads.

I once had the same issue and it turned out that there was no more available disk space on the server, so it couldn't store $_SESSION variables.