Welcome to WebmasterWorld Guest from 54.163.25.166

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

what is Header() function in PHP?

     
8:32 am on May 21, 2012 (gmt 0)

New User from US 

joined:Aug 6, 2011
posts:7
votes: 0


what is Header() function in PHP and For what is this function used in PHP language?
10:27 am on May 21, 2012 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 25, 2004
posts:161
votes: 0


for sending http headers :-)
4:11 pm on May 21, 2012 (gmt 0)

Senior Member

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

joined:Nov 28, 2004
posts:7999
votes: 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";
5:35 pm on May 21, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member eelixduppy is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 12, 2005
posts:5966
votes: 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.
6:13 pm on May 21, 2012 (gmt 0)

Preferred Member

5+ Year Member

joined:Mar 27, 2010
posts:423
votes: 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
9:34 pm on May 21, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 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.