Click to See Complete Forum and Search --> : Session variable lost after header redirect?


Frocer
11-20-2007, 10:32 AM
Hi,

I am having a very bizzare problem that I cannot explain. Basically, my session variable is getting lost through pages (header redirect). So here is the sample code:

page1.php
<?php
session_start();
$_SESSION['test'] = 'test';
header('location:page2.php');
exit;
?>

page2.php
<?php
session_start();
echo $_SESSION['test'];
?>

on page2.php, the echo would be empty... and I can't explain why this is happening. After many hours of googling, it seems like a lot of people are having this problem, but I can't find a solution.

Any idea would be much appreciated! Thanks!

knowj
11-20-2007, 10:35 AM
Do you have cookies disabled?

Frocer
11-20-2007, 12:25 PM
Hi Knowj,

No I don't. The weird thing is -- sometimes it will work, sometimes it doesn't. My only speculation is the session is getting destroyed after the header. Or a new session got started after the redirect. Is that a possibility?