473,326 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Header Processing

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.
Am I correct or will the 'ob_end_clean()' and 'exit()' actually
process.

Tom
Jul 31 '08 #1
4 1423

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

--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
Jul 31 '08 #2
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.
js*******@attglobal.net
==================

Jul 31 '08 #3

Jerry Stuckle schreef:
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.
Hi Jerry,

Good point, Jerry.
If a programmer WANTS to keep executing the script after the
locationheader (some longrunning DB actions eg), this might cause some
hard-to-find bugs.
Since the time the remainder of the scripts has depends on the speed to
the client.

Since I never leave my script running after a Location header, I never
gave that route of problems much thought. ;-)

Hypothetical question: Suppose I deliberately want to keep the script
running after the header("Location.."), will using
ignore_user_abort(TRUE) avoid this problem?

Regards,
Erwin Moller
--
============================
Erwin Moller
Now dropping all postings from googlegroups.
Why? http://improve-usenet.org/
============================
Jul 31 '08 #4
Erwin Moller wrote:
>
Jerry Stuckle schreef:
>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.

Hi Jerry,

Good point, Jerry.
If a programmer WANTS to keep executing the script after the
locationheader (some longrunning DB actions eg), this might cause some
hard-to-find bugs.
Since the time the remainder of the scripts has depends on the speed to
the client.

Since I never leave my script running after a Location header, I never
gave that route of problems much thought. ;-)

Hypothetical question: Suppose I deliberately want to keep the script
running after the header("Location.."), will using
ignore_user_abort(TRUE) avoid this problem?

Regards,
Erwin Moller

Yep, it should, but I would say no guarantee - the web server may
terminate the thread (although I don't know of any cases where it will
for sure). But it would be better to just delay the header() call, if
possible, or start another script as a background task. Then you're
more sure it will not be killed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 1 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Danny Anderson | last post by:
Hola, PHP folk! I have a php page that contains a self-processing form. The form holds search results. The search terms originally came from the previous page, but the user can repeatedly...
10
by: Margaret MacDonald | last post by:
I'm seeing a problem that has me flummoxed. The only thing I can think of is that I'm violating some rule I don't know about. I have some code that does some processing and then does a...
1
by: vb6dev2003 | last post by:
Hi, I have some XML doc loaded in a C# Web Service. XmlDocument doc = new XmlDocument(); doc.LoadXml(myDoc); Code Missing to manipulate header (I would like to replace or manupulate all...
4
by: Andrew Ward | last post by:
Hi All, I was wondering if it is possible to use precompiled headers without having to include a <stdafx.h> or whatever in every source file. My problem is that I have a project that makes heavy...
2
by: sheldonlg | last post by:
I have used the action= statement to send the form to a new page which can get the posted variables. I have used the header("Location: foo.php) statement after testing on the submit with isset....
16
by: a | last post by:
Hi everybody, My config: Win XP (or 2003), Apache 2.0.54, PHP 5.1.2. I have been trying to handle the case of a lenghty opearation on the server while providing the user with feedback and...
6
by: Peter van der veen | last post by:
Hi I have the following problem. I'm calling a webservice from within a VB.net 2005 Windows program. For this i got a WSDL file and loaded that in VB. Until now i just call the webservice and...
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
2
by: mtek | last post by:
Hi, I have a PHP script which performs some processing. And, when that is done, I want to use the 'header' command to load a different page. I read that this command must be the first in the...
4
by: gleery | last post by:
It's often for many pages to share a head part, and if we need to modify the head part, we need to do the same to all other pages. So I wonder if there exists a way to make it easier. How about...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.