Forum Moderators: coopster

Message Too Old, No Replies

php header error

         

laura2k

1:55 pm on Nov 15, 2003 (gmt 0)



Hi,

I had a page that was working perfectly fine, but now all of a sudden when i go to the page i get an error saying:


Warning: Cannot modify header information - headers already sent

However, the actuall site still functions correctly. Is there anyway i can disable this error to be displayed within the script itself?

any advise would be appreciated.

thanks in advance

brotherhood of LAN

2:15 pm on Nov 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can put an @ sign before the header and it will fail silently.

The error is there because you have outputted part of the body and then sent a header. Make sure you are not outputting anything from the script (i.e. echo and print) before the header if you need to use the header.

laura2k

2:48 pm on Nov 15, 2003 (gmt 0)



how do you mean?

i tried putting the following:

<?php
@;
?>

but it doesnt work

brotherhood of LAN

2:50 pm on Nov 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>@ before the header

Try

<?php
echo 'a';
header("Location: [yahoo.com");...]
?>

then try

<?php
echo 'a';
@header("Location: [yahoo.com");...]
?>

laura2k

2:59 pm on Nov 15, 2003 (gmt 0)



i tried both of that but i still get the error and this time its adding an "a" aswell to the top

brotherhood of LAN

3:14 pm on Nov 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Anyone else have PHP and want to try that?

Sorry laura I thought that would solve it. Works fine here.

jamesa

4:21 pm on Nov 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>> Warning: Cannot modify header information - headers already sent

You have to output HTTP headers *before* you output anything else. Make sure there are no echo or print statements, HTML, or even spaces or line breaks (outside of the php tags) anywhere above the section where you output the headers.

HTH

jatar_k

6:21 pm on Nov 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



was there a line number for the error? Such as "ouput started at ...."

You are sending some type of output to the browser before trying to do something else but you haven't mentioned what function or line is giving you the trouble.

laura2k

11:41 pm on Nov 15, 2003 (gmt 0)



yes, its line 1573. But its not within the same file its actually within a include file that my page includes.

any ideas?

BlueSky

12:50 am on Nov 16, 2003 (gmt 0)

10+ Year Member



Open up the file mentioned in the warning error and see if there are any blank lines or spaces above this: <?php

and/or below this: ?>

If so, remove them.

BTW, the @ should have worked. If there are no blank spaces/lines to remove, then find the header commands in your script and prepend an @ symbol on them. What was posted here was merely an example to show how to do this. Those two lines posted here are not supposed to be added...just the the @ symbol on your current header(s). There's a couple other ways to suppress the warning output, but you really should work to resolve the problem instead of just suppressing the warning.

AthlonInside

5:04 am on Nov 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php
header("Location: [yahoo.com");...]
echo 'a';
?>

HEADER must be send before BODY, echo a will create the BODY so it must be after HEADER

or use meta refresh. easy. :)