Forum Moderators: coopster

Message Too Old, No Replies

does header() always work?

sometimes very simple things seem very tough...

         

Anyango

9:03 pm on Feb 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<?
header("Location: http://www.example.com");
?>


Will that always work 100% of the time if it works 1 time ? Yes there is no output before that function call. Will it always work in every browser or there can be any ifs and buts

eelixduppy

9:59 pm on Feb 5, 2010 (gmt 0)



It should as long as you specify a URL not a relative path, then you'll be good.

[edited by: eelixduppy at 5:04 pm (utc) on Feb 6, 2010]

Jonesy

10:36 pm on Feb 5, 2010 (gmt 0)

10+ Year Member Top Contributors Of The Month



Well, there's one "if": Short tags have to be ON to satisfy the example given. And, short tags are deprecated.

jkovar

4:12 am on Feb 7, 2010 (gmt 0)

10+ Year Member



Not 100% of the time. Some people have automatic redirection disabled in their browser, so they'll be given a page that tells them the server wants to redirect them to that URL.

rocknbil

7:38 pm on Feb 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you sure you're not talking about http-meta-refresh there? That is a distinctly different redirection than a location header, and can be disabled by the browser (though I just looked for it in FF, it's not in the general options but may be in about:config . . . ) I don't know that you can disable a location redirect . . . bears some investigation.

Matthew1980

11:02 pm on Feb 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there people,

I always store the base href value in a constant then place that in the header so that every header I use is the complete path name, then I always place an exit; after the header(); just to make sure as nothing further downstream can be set off, is there any need or can it be construed as bad practise? I have always wondered but never really questioned...

Cheers,

MRb

eelixduppy

2:34 pm on Feb 8, 2010 (gmt 0)



The exit after the header calls makes sure you aren't wasting system resources on anything that follows. The PHP parser has to follow all of the code through to make sure that no additional headers are added, so by adding an exit after you are done sending headers, you are not wasting time checking for more before you continue. This is at least my understanding of this. If you aren't sending any more headers after your header call, it's a good idea to add an exit in there.

Matthew1980

3:01 pm on Feb 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there eelixduppy,

Thanks for the clarification, I have always done it, so I will continue to do so!

Cheers,

MRb