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
batatudo
Forum Newbie
Posts: 6
Joined: Tue Dec 30, 2003 6:28 am

Redirect to Another Page

Post 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
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

you have escaped (echo, print.. etc) some characters before you make the header.

show us your code.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post 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.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

err.. why do you have \r\n in ur header function?

*confused*
User avatar
Rob
Forum Commoner
Posts: 33
Joined: Fri Oct 03, 2003 3:18 pm

Post 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.
batatudo
Forum Newbie
Posts: 6
Joined: Tue Dec 30, 2003 6:28 am

Post by batatudo »

You are right

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

thanks.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

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