Redirect to Another Page

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
cscrofani
Forum Newbie
Posts: 7
Joined: Mon May 22, 2006 9:08 pm

Redirect to Another Page

Post by cscrofani »

Hi, I'm looking for a way to redirect to another page. A fellow php user told me to use the 'header' command, as shown here:

Code: Select all

if (empty($zip))
{
	header ("Location: http://data.honoluluacademy.org/zipcode.php");
	exit;
}
but that always gives me some nonsense about header information already being sent.

I just want a simple redirect, instead of sending header information. How can I accomplish this?

There's gotta be a way... It seems a robust language like php wouldn't overlook such a simple function, right?

Thanks,
Chris
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

header() is what you want. The reason you're getting the header information already sent is because the server has sent something down to the client before the header() function is called.

you need to make sure you are not echoing anything out (including whitespace or sending cookies) before you call header().
cscrofani
Forum Newbie
Posts: 7
Joined: Mon May 22, 2006 9:08 pm

Post by cscrofani »

Alrighty, thanks!
Post Reply