Welcome to WebmasterWorld Guest from 54.145.39.186

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

what is Header() function in PHP?

     

ifuturz

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:27 am on May 21, 2012 (gmt 0)

10+ Year Member



for sending http headers :-)

rocknbil

4:11 pm on May 21, 2012 (gmt 0)

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



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

5:35 pm on May 21, 2012 (gmt 0)

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



>> 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

6:13 pm on May 21, 2012 (gmt 0)

5+ Year Member



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

9:34 pm on May 21, 2012 (gmt 0)

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



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month