note 43235 deleted from function.header by bjori
| From: | bjori@php.net | Date: | Mon, 27 Mar 2006 09:55:52 +0000 |
| Subject: | note 43235 deleted from function.header by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-106738@lists.php.net to get a copy of this message | ||
Note Submitter: luzian dot NO at SPAM dot london dot com
----
Just a reminder if you use sessions: Be careful when you want to use
header('Location: XXX');
as a redirect to XXX. In fact, previously written session variables might not be correctly written,
which results in loss of these variables in the called script. So if you use sessions, ALWAYS use
session_write_close();
BEFORE a header redirect. This makes sure that the session variables previously set by
$_SESSION['foo'] = bar; or session_register('foo'); are actually written to the
session database before the script is terminated. So a tasty bit of code would be:
<?php
// whatever you do before, including setting session variables
$foo = "bar"
session_register('foo');
$_SESSION['foo2'] = $foo; // etc.
// so now the important part:
session_write_close(); // write session
header("Location: http://server.com/file.php"); // redirect
exit(); // terminator :o)
// that's it!
?>