Re: $_SESSION variable gets lost on FORM action

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux