Re: One more 'Headers Already Sent' error. :-(
| From: | Brad Melendy | Date: | Tue, 25 Jun 2002 22:07:33 +0000 |
| Subject: | Re: One more 'Headers Already Sent' error. :-( | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-103847@lists.php.net to get a copy of this message | ||
Well, I have traced this down to line 4 in the following code
'include("header.html");' which just includes my navigation bar. If I
comment it out, everything works great, if I leave it in, I get the error
Headers Already Sent. The file it purely html. What could be the problem??
Thanks in advance!
<?php
error_reporting(2039);
include("dblib.inc");
include("userlib.inc");
include("header.html");
$message="";
if ( isset( $actionflag ) && $actionflag == "login" )
{
if ( empty( $form[login] ) || empty( $form[password] ) )
$message .= "You must fill in all fields<br>\n";
if ( ! ( $row_array = checkPass( $form[login], $form[password] ) ) )
$message .= "Incorrect password. Please try again<br>\n";
if ( $message == "" ) // we found no errors
{
LastLogin($row_array[login]);
cleanSession( $row_array[id], $row_array[login], $row_array[password] );
header( "Location: index.php?".SID );
}
}
?>
"Brad Melendy" <brad@techknow.biz> wrote in message
news:20020625200359.74200.qmail@pb1.pair.com...
> Hi All,
> I know this has come up before and I've read some posts so far, but this
is
> still eluding me.
>
> I have come to understand that typically, if you are getting an error
> message about your headers having already been sent to the browser, you
are
> writing bad code. Now, I want to right good code so I really want to
figure
> this out the right way and stay away from doing stuff like setting Output
> Buffering to ON in the php.ini file, (which I can do in my case).
>
> So, basically, I get the error message:
>
> "Warning: Cannot add header information - headers already sent by (output
> started at /home/bmelendy/websites/www.e-learn.net/quizD/header.html:3) in
> /home/bmelendy/websites/www.e-learn.net/quizD/login.php on line 17"
>
> Now, I can see right on line 17 that I'm outputting a header with the
> following line:
>
> header( "Location: index.php?".SID );
>
> This is part of an if/then statement that is supposed to redirect the user
> to index.php upon login. The conflict occurs because I have an include
file
> with a function checkUser() that also redirects the user to the login.php
> page if they fail the the check with a line:
>
> header( "Location: /main/login.php" );
>
> So, is there no way for me to redirect a user from both a function under
> certain circumstances and also from withing a page that calls that
function?
> I don't completely understand when exactly the headers are being sent and
> this does all work properly if I turn the Output Buffering to 'ON' in the
> php.ini file, but I'd like to try to make this work the 'right' way rather
> than cut corners and just make the server work for my code, instead of
> making my code work for the server. ;-)
>
> Thanks very much for any input.
>
> ...Brad
>
>