note 80365 deleted from function.session-write-close by betz
| From: | betz@php.net | Date: | Mon, 17 Mar 2008 13:39:31 +0000 |
| Subject: | note 80365 deleted from function.session-write-close by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137127@lists.php.net to get a copy of this message | ||
Note Submitter: thales at crazymania dot com dot br
----
One more note using Header("Location...") with sessions. Still didn't find how to
solve.
This works:
<?php
//file /thisfile.php
session_start();
if(isset($_GET['secondtime'])) {
print_r($_SESSION);
die();
}
if(!session_is_registered("test")) {
session_register("test");
$_SESSION['test']="hi";
session_write_close();
Header("Location: thisfile.php?secondtime");
}
?>
The result is: when trying to access /thisfile.php, at first the variable "test" from
session is not registered. Then the scripts registers it and then force the browser to redirect to
the same page, but with $_GET['secondtime'] set. So it prints out the session content,
showing the variable "test".
This doesn't work:
<?php
//file /thisfile.php
session_start();
if(isset($_GET['secondtime'])) {
print_r($_SESSION);
die();
}
if(!session_is_registered("test")) {
session_register("test");
$_SESSION['test']="hi";
session_write_close();
Header("Location: /thisfile.php?secondtime");
}
?>
The result is: when trying to access /thisfile.php, at first the variable "test" from
session is not registered. Then the scripts registers it and then force the browser to redirect to
the same page, but with $_GET['secondtime'] set. So it prints out the session content, NOT
showing the variable "test".
Why? Because when the folder from the actual file is passed to the browser redirection path, the
PHPSESSID cookie seems not to be found after the redirection. I've already forced setcookie()
and Header("Set-Cookie") to the path wanted. Nothing happens...