help regarding redirect using header(location : "")

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aliasnikhil
Forum Newbie
Posts: 3
Joined: Sun Mar 20, 2011 10:50 am

help regarding redirect using header(location : "")

Post 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.
aliasnikhil
Forum Newbie
Posts: 3
Joined: Sun Mar 20, 2011 10:50 am

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

Post 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.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

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

Post 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.
aliasnikhil
Forum Newbie
Posts: 3
Joined: Sun Mar 20, 2011 10:50 am

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

Post by aliasnikhil »

thanks a lot,it worked :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post by pickle »

This is about PHP code, not General Discussion. Moving thread.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

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

Post 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.
Post Reply