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
User avatar
SKJoy
Forum Newbie
Posts: 9
Joined: Wed Sep 29, 2004 8:34 am
Location: Dhaka, Bangladesh.
Contact:

Post by SKJoy »

In my case, this location function triggers the error
Warning: Cannot modify header information - headers already sent by
Any idea?
User avatar
SKJoy
Forum Newbie
Posts: 9
Joined: Wed Sep 29, 2004 8:34 am
Location: Dhaka, Bangladesh.
Contact:

Post by SKJoy »

Alternatively, I am using
Click <a href="<?php echo($_SERVER["SCRIPT_NAME"] . "?Area=quizscheme");?>">here</a> if your browser doesn't redirect to quiz list page.

<script language="JavaScript">
document.location = '<?php echo($_SERVER["SCRIPT_NAME"] . "?Area=quizscheme");?>';
</script>
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Answer to header problem here: viewtopic.php?t=1157
Breckenridge
Forum Commoner
Posts: 62
Joined: Thu Sep 09, 2004 11:10 pm
Location: Breckenridge, Colorado

Post by Breckenridge »

You will get this warning:
Warning: Cannot modify header information - headers already sent by

if your code does output anything to the browser including a blank char before the header is sent to the browser.

Just make sure that your headers are executed before any output is made and it should work.
User avatar
SKJoy
Forum Newbie
Posts: 9
Joined: Wed Sep 29, 2004 8:34 am
Location: Dhaka, Bangladesh.
Contact:

Post by SKJoy »

I have read the issue that triggers the error and I agree with the reason.

But the trouble is that I am using the FuseBox architechture in PHP, thus it is really not possible to prevent from outputing something to the browser before the location(); function as there are so many templates are being included dynamically. I am using the form's action attribute as action="<? echo($_SERVER["SCRIPT_NAME"]);?>?Area=SomeArea&Action=SomeAction", so all the templates are being processed by the PHP interpreter no matter if I make any output in the template holding the location(); function or not.

Pleease help me if there is some other way of PHP's native than JavaScript stuff!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you're moving quickly into threadjacking SKJoy.. look into [php_man]ob_start[/php_man](), although I personally dislike using it...
User avatar
SKJoy
Forum Newbie
Posts: 9
Joined: Wed Sep 29, 2004 8:34 am
Location: Dhaka, Bangladesh.
Contact:

Post by SKJoy »

although simple to implement but that doesn't seem to be invented for my need & it's kinda Cannon for the mosquito!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it was created for this need... among others..

unless you want to reorder and fix all your includes so they don't output anything until you've had a chance to process the redirection need, I'd suggest using it.
User avatar
SKJoy
Forum Newbie
Posts: 9
Joined: Wed Sep 29, 2004 8:34 am
Location: Dhaka, Bangladesh.
Contact:

Post by SKJoy »

Even if I use ob_start(), I got to put it right at the begining of the whole scripting, likely to be in APPLICATION.PHP or in HEADER.PHP. This will cause the use of the function everytime the application has a browser call no matter I need the functionality or not, not a good idea!
Breckenridge
Forum Commoner
Posts: 62
Joined: Thu Sep 09, 2004 11:10 pm
Location: Breckenridge, Colorado

Post by Breckenridge »

Why not just use javascript?
User avatar
SKJoy
Forum Newbie
Posts: 9
Joined: Wed Sep 29, 2004 8:34 am
Location: Dhaka, Bangladesh.
Contact:

Post by SKJoy »

Breckenridge wrote:Why not just use javascript?
Please care to read my earlier post (#2).
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Why would you need to have a template on a page that WONT BE SEEN?
User avatar
SKJoy
Forum Newbie
Posts: 9
Joined: Wed Sep 29, 2004 8:34 am
Location: Dhaka, Bangladesh.
Contact:

Post by SKJoy »

LiLpunkSkateR wrote:Why would you need to have a template on a page that WONT BE SEEN?
Dear, do you always use templates to output something to the browser? Please study the FuseBox technic, that will be helpful for you.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

SKJoy wrote:
LiLpunkSkateR wrote:Why would you need to have a template on a page that WONT BE SEEN?
Dear, do you always use templates to output something to the browser? Please study the FuseBox technic, that will be helpful for you.
Just to clear up some confusion: this is a PHP forum, not a fusebox forum. While fusebox is PHP-based, it is just one of tens of thousands applications written in PHP. The PHP solution to your problem has been suggested to you. If that doesn't work for you for the simple reason that you use fusebox, I'd suggest consulting a fusebox support forum like http://bombusbee.com/.
Post Reply