Jump to content

Session Variables Being Partially Lost After Redirect


Go to solution Solved by 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.

  • Solution

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.