note 80365 added to function.session-write-close
| From: | thales at crazymania dot com dot br | Date: | Sat, 12 Jan 2008 01:47:43 +0000 |
| Subject: | note 80365 added to function.session-write-close | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135047@lists.php.net to get a copy of this message | ||
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...
----
Server IP: 69.147.83.197
Probable Submitter: 201.70.107.12
----
Manual Page -- http://www.php.net/manual/en/function.session-write-close.php
Edit -- https://master.php.net/note/edit/80365
Del: integrated -- https://master.php.net/note/delete/80365/integrated
Del: useless -- https://master.php.net/note/delete/80365/useless
Del: bad code -- https://master.php.net/note/delete/80365/bad+code
Del: spam -- https://master.php.net/note/delete/80365/spam
Del: non-english -- https://master.php.net/note/delete/80365/non-english
Del: in docs -- https://master.php.net/note/delete/80365/in+docs
Del: other reasons-- https://master.php.net/note/delete/80365
Reject -- https://master.php.net/note/reject/80365
Search -- https://master.php.net/manage/user-notes.php