note 57875 added to function.session-start

From: Date: Mon, 17 Oct 2005 18:13:20 +0000
Subject: note 57875 added to function.session-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-97124@lists.php.net to get a copy of this message
foltscane at yahoo dot com wrote about people losing session information on page redirects. The problem is some times the redirect may kick you off to the next page before all the session variables have been saved. The true solution to lost session vars on redirect is to simply call session_write_close(); before setting the redirect header. This will insure that php finishes writing the session info before page redirect gets underway. ie: <? session_start(); $_SESSION['forward'] = "This session data will not be lost!"; session_write_close(); header('Location: nextpage.php'); ?> ---- Manual Page -- http://www.php.net/manual/en/function.session-start.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57875 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57875&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57875&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57875&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57875&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57875&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57875&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57875&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57875&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#97124) next »