trouble with header()

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
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

trouble with header()

Post by anthony88guy »

I get this error when I am trying to use header.
Warning: Cannot modify header information - headers already sent by (output started at /home/********/public_html/***********.php:30) in /home/******/public_html/********** on line 119
Last edited by anthony88guy on Thu May 12, 2005 6:01 pm, edited 3 times in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Hey ma, we got a tutorial for this. :?

:arrow: viewtopic.php?t=1157
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

You've already output HTML data. You should buffer it in some way (for example, output buffering controls), or do something else to ensure that no output is sent to the browser before the header is sent.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Bennettman wrote:...You should buffer it in some way (for example, [url=http://uk.php.net/manual/en/function.ob-start.php]output buffering controls...[/url
That is a bandaid approach to the problem. Better yet, design your app's properly so that all your output is sent at the end of your program execution. ;)
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

Sometimes, bandaid is better (though I hate to say it ;p) than uprooting an existing script if it's practically done ^_-

But yeah, what Jcart said is absolutely right, it offers plenty of advantages in the end and is cleaner than constant output.
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

Ok thanks, so I need to add "ob_start()" in the beginning of the page and "ob_end_flush()" at the end. What’s bandaid? Writing script that takes less bandwidth?
Bennettman
Forum Contributor
Posts: 130
Joined: Sat Jun 15, 2002 3:58 pm

Post by Bennettman »

A bandaid approach is one where you apply quick fixes which don't make the code itself more effective, but do the job. Like putting on a bandaid/plaster when something goes wrong instead of stopping the problem from happening in the first place (or going to the trouble of preventing it happening again if it does).
anthony88guy
Forum Contributor
Posts: 246
Joined: Thu Jan 20, 2005 8:22 pm

Post by anthony88guy »

Bennettman wrote:A bandaid approach is one where you apply quick fixes which don't make the code itself more effective, but do the job. Like putting on a bandaid/plaster when something goes wrong instead of stopping the problem from happening in the first place (or going to the trouble of preventing it happening again if it does).
I feel dumb, it works now.
Post Reply