Page 1 of 1

help regarding redirect using header(location : "")

Posted: Sun Mar 20, 2011 11:03 am
by aliasnikhil
i am trying to create a page "welcome.php" which takes in information and i get all things working except the redirect when user submits the page.
i used header("location : about.php") for redirect but it doesnt redirect to that page.instead it displays a blank page with the address in address bar remaining same as previous page i.e "welcome.php".if i add an echo "hii"; line below the header() then it prints hii on the page and this time also with the address in address bar remaining same as previous page.
please help.any help would be very much appreciated.
Thanks in advance.

Re: help regarding redirect using header(location : "")

Posted: Sun Mar 20, 2011 11:20 am
by aliasnikhil
i found out a solution
i typed header(location : "about.php");
i removed the space and retyped it as header(location:"about.php");
it worked but now the problem is it works with firefox but chrome gives the same problem as before.

Re: help regarding redirect using header(location : "")

Posted: Sun Mar 20, 2011 1:39 pm
by McInfo

Code: Select all

header('Location: about.php');
exit;
For complete compliance with the standard (as described in section 14.30 of RFC 2616), the first letter of "Location" should be capitalized and an absolute URI should be used. A relative URI usually works, however.

Call exit() or die() after declaring a location header to prevent execution of any code appearing after that point, which could have unintended consequences.

Read PHP Manual: header() for additional important notes.

Re: help regarding redirect using header(location : "")

Posted: Mon Mar 21, 2011 8:03 am
by aliasnikhil
thanks a lot,it worked :)

Re: help regarding redirect using header(location : "")

Posted: Mon Mar 21, 2011 10:36 am
by pickle
This is about PHP code, not General Discussion. Moving thread.

Re: help regarding redirect using header(location : "")

Posted: Mon Mar 21, 2011 11:22 am
by John Cartwright
McInfo wrote:

Code: Select all

header('Location: about.php');
exit;
For complete compliance with the standard (as described in section 14.30 of RFC 2616), the first letter of "Location" should be capitalized and an absolute URI should be used. A relative URI usually works, however.

Call exit() or die() after declaring a location header to prevent execution of any code appearing after that point, which could have unintended consequences.

Read PHP Manual: header() for additional important notes.
Older browsers may not understand relative paths, however. It is best to use absolute paths, just in case.