headers already sent error

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
duncan
Forum Newbie
Posts: 8
Joined: Sun Sep 17, 2006 7:07 am

headers already sent error

Post by duncan »

How could I rewrite this code so that while the page is redirecting, a message such as "please wait... you are being redirected" is shown without a "headers already sent" error?

Using this buffer method does not work... The page is redirected without errors but without the "please wait" message.

I don't want to use meta refresh nor javascript because these can be disabled in the browser options.

Code: Select all

<?php
ob_start();

echo "<p>please wait... you are being redirected</p>";

header("Location: somepage.php");

ob_end_flush();
exit;
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Output buffering is not an answer to this "problem."

viewtopic.php?t=1557
duncan
Forum Newbie
Posts: 8
Joined: Sun Sep 17, 2006 7:07 am

Post by duncan »

I don't understand how that url is related to php header.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

use a meta refresh... but then supply the user with a link in case meta refresh doesn't work... that's kinda the standard way of doing things. You can't echo out data and then send a header. It doesn't work that way... a header is exactly that, a header, so it would be send BEFORE any data. There is no way to send data before headers... EVER
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

duncan wrote:I don't understand how that url is related to php header.
Sorry, posted the wrong link

viewtopic.php?t=1157
Post Reply