homepage Welcome to WebmasterWorld Guest from 54.227.5.234
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
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:4455839
 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




msg:4455882
 10:27 am on May 21, 2012 (gmt 0)

for sending http headers :-)

rocknbil




msg:4456001
 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




msg:4456058
 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:4456071
 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




msg:4456142
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved