Page 1 of 1

Redirect to Another Page

Posted: Tue Dec 30, 2003 6:28 am
by batatudo
Hi All

I'm using the following command to redirect the user to another page.

header( "location: http://www.msn.com\r\n" );

But I allways received the following error message.

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/redirect.php:19) in /var/www/html/redirect.php on line 88

Does anyone can tell me what's the problem since I think I didn't send any headers before this command is executed.

thanks

Posted: Tue Dec 30, 2003 7:10 am
by AVATAr
you have escaped (echo, print.. etc) some characters before you make the header.

show us your code.

...

Posted: Tue Dec 30, 2003 1:15 pm
by kettle_drum
Yeah you have to make sure that the header is the FIRST thing that you send to the user. So make sure you have echoed anything, or put html before the php script etc.

Posted: Tue Dec 30, 2003 6:01 pm
by d3ad1ysp0rk
err.. why do you have \r\n in ur header function?

*confused*

Posted: Tue Dec 30, 2003 6:13 pm
by Rob
Your getting the error because that method of refreshing is horrible. Heres my simple method I always use

Code: Select all

<?
echo ("<meta http-equiv='refresh' content="0;URL=www.google.com'>");
?>

it will work no matter where it echos.

Posted: Tue Dec 30, 2003 8:25 pm
by batatudo
You are right

Both methods works, I have a few bugs in my code.

thanks.

Posted: Tue Dec 30, 2003 8:35 pm
by d3ad1ysp0rk
If i want to execute code then send them somewhere, i use header
if i want to display something (like "thanks for signing up! you'll be redirected to login in 5 seconds...") then i use meta