#14636 [Com]: Session variables are lost when redirecting to a url using header() function.
| From: | brett dot crosby at australiswebtech dot com dot au | Date: | Thu, 29 Jan 2004 11:53:31 +0000 |
| Subject: | #14636 [Com]: Session variables are lost when redirecting to a url using header() function. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-54116@lists.php.net to get a copy of this message | ||
ID: 14636
Comment by: brett dot crosby at australiswebtech dot com dot au
Reported By: kannan at tmsassociates dot com
Status: Bogus
Bug Type: Session related
Operating System: windows 2000 professional
PHP Version: 4.0.6
New Comment:
Have experienced the same problem where an application works fine on
LAMP and not on Win2k. One thing that I did notice (by accident - I
turned on debugging to see what was happening) is that if I send some
output to the second page prior to the header() command the session
variable was registered. I'm then able to shut down the browser and
restart without problems. However, if I reboot my machine, I must send
the debug output again.
Note to self: Perhaps there is a way of sending some data to the
browser that will instantiate the session but clear the buffer before
sending the 'real' data?
Previous Comments:
------------------------------------------------------------------------
[2004-01-23 01:53:12] moon_wizard at yahoo dot coom
I just ran into the same issue. I set up PHP and Apache on my home
Windows machine. I was able to successfully set SESSION variables and
recover after a header() call.
When I moved the file to my hosting provider, the SESSION variables
were lost. I think that my hosting provider might be using IIS.
I tried the session_write_close() with no success.
John Gregory
------------------------------------------------------------------------
[2004-01-13 15:34:34] mgandalf at seznam dot cz
Hi, I just look at your source and php.ini and it was clear
to me. Problem is here: "session.cookie_path = c:\temp".
It is not path to file but path on web server where is
cookie valid. So change it to "session.cookie_path = /"
and it will work. When it is for example "/dir_name",
cookie is valid just for http://server/dir_name/, but not
for http://server/dir_name2/ and in this 2nd case will not be
sent.
Gandalf
------------------------------------------------------------------------
[2004-01-09 17:47:15] writeto_ben at hotmail dot com
I would have liked a simple header redirect as well, but unfortunately
the other suggestions didn't solve the issue. However, setting a
javascript redirect seemed to do the trick. I'm using Win2k
professional, IIS 5.0, PHP Version 4.3.4
This will work on IE browsers. Just modify the javascript for netscape
compatibility.
<?
//...perform login check, produce $errStr if fails
if($errStr){
header("Location: login.php?err=".$errStr);
}else{
print '<html>
<body
onload=eval("window.location.href=\'http://blahblahblah/default.php\';");></body>
</html>';
}
?>
------------------------------------------------------------------------
[2003-12-05 23:28:10] venki_cute123 at rediffmail dot com
i have a session variable to be accessed in same page but submit twice
in same page at third time I am not able to access session variable
------------------------------------------------------------------------
[2003-11-22 18:18:19] andrew dot whale at which dot net
Hi
I've also had a similar problem of session variables not being passed
following a call to header(). I am running PHP 4.0.15 on an XP m/c.
The following worked for me, by placing a session_write_close() before
the call to header, followed by and exit():
session_write_close();
header("Location: $strPage");
exit();
I hope this will be of use to some.
Andrew Whale
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/14636
--
Edit this bug report at http://bugs.php.net/?id=14636&edit=1