PHP Bugs  
php.net | support | documentation | report a bug | advanced search | search howto | statistics | login

go to bug id or search bugs for  

Bug #13933 error_log and HTTP redirect using header conflict
Submitted:5 Nov 2001 9:11am UTC Modified: 5 Feb 2002 6:34pm UTC
From:bonseb at free dot fr Assigned to:yohgaki
Status:Closed Category:Output Control
Version:4.0.6 OS:Windows NT4 SP6
View/Vote Developer Edit Submission

[5 Nov 2001 9:11am UTC] bonseb at free dot fr
[Might be related to bug #11213]

Using :
NT4 SP6
Apache 1.3.20
PHP 4.0.6
Zend Optimizer 1.1 (bug reproduced without also)

I have a quite short PHP page needing to log something, and then switch
to another PHP page.

I use the following PHP code :

error_log ($message, 0);
header("Location: new-location.php");

I then get the following error message :
Cannot add header information - headers already sent

If I remove the call to error_log, the problem disappears, but I won't
get the event logged :( Thus, error_log must be 'the one' producing the
unexpected output.

If I swap the two calls, (header first, then error_log), I'll get to
new-location.php, but nothing will get logged :(

If I specify a filename in the call to error_log, and leave it in second
position (see following example), it works fine (except I don't
automatically get the date and IP address of client like I used to get
in Apache's log).

error_log ($message, 3, 'd:/program files/apache
group/apache/logs/error.log');

Here is my PHP configuration regarding logging functions :

error_reporting  =  E_ALL & ~E_NOTICE
display_errors = On
display_startup_errors = Off
log_errors = On

Let's add another strange behaviour. If I add the following line in
php.ini :
error_log = d:/program files/apache group/apache/logs/error.log
and execute again the first example (error_log with 2 args and then
header), it works fine :)

Any clues ?
[12 Nov 2001 5:01pm UTC] zak@php.net
Sounds like error_log() was generating an error message 
because the error_log directive was not set. Once the 
error message was generated, output would be sent to the 
browser, causing the headers to be sent and the header() 
call to fail.

Try unsetting the error_log directive in php.ini and run a 
script that only calls error_log().
[12 Nov 2001 7:54pm UTC] sniper@php.net
Status -> feedback (Zak! try to remember? :)
[5 Dec 2001 4:24am UTC] bonseb at free dot fr
I finally found time to test. Here it goes. 

First of all, PHP config is:
error_log is not set
display_errors is off
log_errors is on
error_reporting is standard (E_ALL & ~E_NOTICE)

Then, the page I'm testing:
<?
error_log ("this is a test", 0);
header("Location: index.php");
?>

And finally, the results:
- in Apache's log file, I get these two lines:
[Wed Dec 05 10:09:59 2001] [error] [client 172.22.50.91] this is a test
[Wed Dec 05 10:09:59 2001] [error] [client 172.22.50.91] PHP Warning: 
Cannot add header information - headers already sent in
d:\wwwroot\htdocs\csf_recette\titi.php on line 3

- the source of the generated page displayed in IE is as follow,
eventhough nothing has been output:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html;
charset=iso-8859-1"></HEAD>
<BODY></BODY></HTML>

Conclusion:
- error_log works fine, it does what I expect, but it might do a little
more;
- PHP complains about something being output *before* the call to
header. I've tried removing this call (to header), my message is logged,
and I *still* get the same output;
- thus, somehow, the call to error_log produces PHP or Apache to
generate this unexpected HTML code while logging;

I've tried almost the same settings on another server (difference in
php.ini is display_errors on) and it works quite fine.

Could there be other parts of PHP's configuration, or even Apache's
conf, altering the expected behaviour ?
[10 Dec 2001 8:40pm UTC] zak@php.net
Assigning it to myself so that I don't forget about it. :)
[12 Dec 2001 4:51am UTC] yohgaki@php.net
Zak,  is this bug analyzed?
I'm trying to sort out output buffering problems.
Thanks.
[31 Dec 2001 7:17pm UTC] zak@php.net
Assigning this to Yasuo :)
[5 Feb 2002 6:34pm UTC] yohgaki@php.net
This bug has been fixed in CVS.

RSS feed | show source 

PHP Copyright © 2001-2009 The PHP Group
All rights reserved.
Last updated: Sat Nov 21 10:30:49 2009 UTC