note 43235 added to function.header

From: Date: Tue, 15 Jun 2004 00:25:22 +0000
Subject: note 43235 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-71072@lists.php.net to get a copy of this message
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! ?> ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43235 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43235&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43235&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#71072) next »