homepage Welcome to WebmasterWorld Guest from 54.197.211.197
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
what is Header() function in PHP?
ifuturz



 
Msg#: 4455837 posted 8:32 am on May 21, 2012 (gmt 0)

what is Header() function in PHP and For what is this function used in PHP language?

 

delboy1978uk

10+ Year Member



 
Msg#: 4455837 posted 10:27 am on May 21, 2012 (gmt 0)

for sending http headers :-)

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4455837 posted 4:11 pm on May 21, 2012 (gmt 0)

manual [php.net]

PHP has a lot of functions to do the same thing that you have to do manually in other languages. This

Header("location:http://www.example.com");

is identical to this

print "location:http://www.example.com";

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4455837 posted 5:35 pm on May 21, 2012 (gmt 0)

>> is identical to this

Not exactly...


The second special case is the "Location:" header. Not only does it send this header back to the browser, but it also returns a REDIRECT (302) status code to the browser unless the 201 or a 3xx status code has already been set.

matrix_jan



 
Msg#: 4455837 posted 6:13 pm on May 21, 2012 (gmt 0)

Hi ifuturz, welcome to WW.

Like mentioned above header is used for redirection (using "location"). Also you can use header function for setting the HTTP return code of the document, such as:

header('HTTP/1.0 404 Not Found');

But you can't have anything printed prior this (it will automatically return 200), so put it as high in the conditional code as possible.

Good luck

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4455837 posted 9:34 pm on May 21, 2012 (gmt 0)

HEADER("Location: http://www.example.com");

Add a trailing slash after the .com part. The canonical URL should include a trailing slash.

Make sure you set this as a 301 redirect. The default as coded above is for a 302 redirect.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved