473,761 Members | 9,284 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Header Processing

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

ob_start();
session_name('f oo');
session_start() ;
if (!$_SESSION['bar']) {
header("Locatio n: http://" . $_SERVER['HTTP_HOST'] .
dirname($_SERVE R['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 1446

Call Me Tom schreef:

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

ob_start();
session_name('f oo');
session_start() ;
if (!$_SESSION['bar']) {
header("Locatio n: http://" . $_SERVER['HTTP_HOST'] .
dirname($_SERVE R['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.Redire ct.
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("Locatio n...") 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("Locatio n: http://" .
$_SERVER['HTTP_HOST'] . dirname($_SERVE R['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.Redire ct.
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("Locatio n...") 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*******@attgl obal.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("Locatio n: http://" .
$_SERVER['HTTP_HOST'] . dirname($_SERVE R['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.Redire ct.
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("Locatio n...") 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("Locatio n.."), will using
ignore_user_abo rt(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_star t();
if (!$_SESSION['bar']) { header("Locatio n: http://" .
$_SERVER['HTTP_HOST'] . dirname($_SERVE R['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.Redire ct.
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("Locatio n...") 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("Locatio n.."), will using
ignore_user_abo rt(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*******@attgl obal.net
=============== ===
Aug 1 '08 #5

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

Similar topics

1
3140
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 refine the results on the page in question until the target item can be found. This search refinement is where the self-processing form comes to play. The search results are listed in a table with a radio button at the end of each row. What I...
10
5673
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 header('Location: ...) jump to page A on success or falls through to the jump to page B. This is the code: if ( mysql_query( 'LOCK TABLES tableX WRITE', $link ) ) { mysql_query( $q, $link ) ; // store the record
1
3261
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 these XXXXX): <mso-XXXXXX productversion="XXXXXX"> <mso-application progid="XXXXX"?>
4
2516
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 usage of a large third party library which means after pre-processing each translation unit is around 1meg in size. There are reasons though why I cannot use the standard approach to precompiled headers. What I would like to do is somthing like...
2
2363
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. What I want to know is if they can be combined. That is, test first with the isset, and if no errors go to the action call. Simply going with the header call doesn't seem to send the form variables.
16
2915
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 ability to cancel, and nothing seems to work so far. The following code is one attempt to address this, and it is called as result of a POST:
6
43062
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 everything works OK. Now i need to add an extra attribute/header element to the SOAP header before i contact the webservice.
6
3990
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 string UID; public string PWD; }
2
1318
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 script, before anything else is put to the screen. I have a bunch of coding to define variables and store them in a MySQL database, but nothing goes to the screen.
4
1083
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 take the header out and request in ajax way?
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3911
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.