Re: Header Processing



Erwin Moller wrote:

Call Me Tom schreef:

Hi Tom,

I was looking at an application with the following code snippet:

ob_start();
session_name('foo');
session_start();
if (!$_SESSION['bar']) { header("Location: http://"; . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/index.php");
ob_end_clean();
exit();
}

I am under the impression that the "header" redirection is immediate.

That is wrong.
This is not like, for example ASP/VB's Response.Redirect.
header() function in PHP does excact what it says and nothing more: Setting a header.

Am I correct or will the 'ob_end_clean()' and 'exit()' actually
process.

They will be processed.


Tom

Bottomline: If you need a 'redirect' via header("Location...") always call exit after that, or the script will merely run on untill it ends.

Regards,
Erwin Moller


Almost correct, Erwin,

The script will continue until the redirect actually takes place. That will be after the header is sent to the client and the client responds.

So while the rest of this script will run, another script with a relatively long run time probably will be interrupted.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================

.



Relevant Pages

  • Re: Problem with ASP on Webserver
    ... There is no ActiveX object involved in this problem, we only request a ASP ... function in the script ... (Accept-Language:) ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Problem with ASP on Webserver
    ... There is no ActiveX object involved in this problem, we only request a ASP ... function in the script ... (Accept-Language:) ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Problem with ASP on Webserver
    ... the script we sometimes ... (Accept-Language:) ... NextLine: OK ...
    (microsoft.public.windowsce.platbuilder)
  • Re: How can I get this redirect to work? (and this mail function)
    ... return TRUE after the first header() call, ... Even on a redirection header the script continues to run until it ... As soon as you do something which sends the headers the user can abort the connection. ...
    (comp.lang.php)
  • Re: Problem with ASP on Webserver
    ... Entrek's TOOLBOX is a lot better for memory stuff. ... the script we sometimes ... (Accept-Language:) ...
    (microsoft.public.windowsce.platbuilder)