Jump to content

Session Variables Being Partially Lost After Redirect


phdphd

Recommended Posts

Hi All,
I am facing a strange problem with session variables being partially lost after redirect.
I recently moved from a wampserver/php 5.3.5 environment to a UwAmp/php 5.4.15 environment. I am using the same php files and scripts in both environments.
In one of the scripts there are session variables being set and also a "header('Location: page.php');" statement.
Everything works perfectly in the older environment. However, in the newer one, session variables belonging to the same script as the "header('Location: page.php');" statement are lost, while all other session variables previously set in other scripts are kept.
The problem persists if I use a UwAmp/php 5.3.5 environment.
Any idea of where the problem comes from ?
Thanks!

It is possible that the "old" environment has output buffering turned on and the script in question has some output before the call to session_start(). If the "new" environment has output buffering turned off an error occurs with the call to session_start(), and the session is not actually started, so no new values can be assigned to the session.

 

Turn on error_reporting() for the development server and fix any errors (or warnings or notices) that occur.

And the winner is .... David !

The warning I get is of type "Cannot modify header information - headers already sent by  (output started at C:\UwAmp\www\.....\page.php:XX) in C:\UwAmp\www\.....\page.php.php on line YY...."

At XX level, there is print_r($_SESSION);, while YY corresponds to the line where the header('Location: page.php') is located.

I solved the issue by setting output_buffering to On in the php.ini file.

 

Thank you very much David!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.