Re: $_SESSION variable gets lost on FORM action

From: Date: Tue, 09 Jan 2007 23:00:04 +0000
Subject: Re: $_SESSION variable gets lost on FORM action
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-247196@lists.php.net to get a copy of this message
Nuno Oliveira wrote:
Sometimes in my code I use the Header('Location: index.php?var=value'); and I've found out (I think) that when one of these headers are executed by PHP, the rest of the script gets executed. I'm thinking that this is the problem because I've eliminated all the occurrences where the SESSION var was cleared until only one exists and it was after a Location Header. I've put an exit(); after the header and the problem was gone... :) Is this the correct PHP/HTML behavior or is there another problem? Am I supposed to put an exit(); after a header "Location" to make sure that no more code gets executed?
Redirecting using a Location header is not the only thing you can do with the header() function. It will never end processing of the script no matter what you pass to it. The example on the manual page for the header() function says as much (http://php.net/header), you read that right? <?php header("Location: http://www.example.com/"); /* Redirect browser */ /* Make sure that code below does not get executed when we redirect. */ exit; ?> -Stut

« previous php.general (#247196) next »