This is my code:
// Save stuff to session
$_SESSION['uid'] = $uid;
$_SESSION['name'] = $user_profile[name];
// Redirect to test page
header( 'Location: http://www.justwalk.it/test.php' ) ;
If I print session instead of redirecting I get it with no problems:
Array ( [uid] => xx [rank] => xx [name] => xx )
However when redirecting in test.php I already can’t print the session. The only code in test.php it is:
<? session_start();
print_r($_SESSION);?>
But it prints array() and $_SESSION['uid'] doesn’t return anything at all.
I don’t believe the session has been unset as it sometimes pops out in other places on my page. It’s simply not accessible all the time. And I don’t know why. What am I doing wrong? Or if I’m not doing anything wrong what could be the reason for this problem?
If there is no code unsetting the session, it might be worth checking if you are accessing the original script using the non-www version of your URL and then redirecting to the www one.
Another cause could, as T1000 mentioned, be output being sent before
session_start(), UTF8 BOM character is notorious for causing sometimes invisible output.