php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22079 logging warnings causes header() to fail
Submitted: 2003-02-05 12:30 UTC Modified: 2003-02-05 17:26 UTC
From: zlo at canada dot com Assigned:
Status: Closed Package: Output Control
PHP Version: 4CVS-2003-02-05 (stable) OS: RedHat 7.2
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: zlo at canada dot com
New email:
PHP Version: OS:

 

 [2003-02-05 12:30 UTC] zlo at canada dot com
What i am trying to do: send headers
What happens: headers don't get sent under the excuse that "output already started" if any messages have been logged by error_reporting, although no output has been sent to the browser. (logging goes to error_log) If i disable reporting E_NOTICE or logging, problem disappears.

this happens under php 4.3.0 and the fresh snapshot from Feb 5, when used in cgi mode in the following ways:
Action php-script /php4/php
-or-
#!/usr/bin/php
it DOES NOT happen under mod_php 4.3.0

code that exhibits the problem:
(i expect to get redirected to ok.php but i see hi instead)
if i remove the errorneous line that causes warnings, it works as intended.
<?php
$res=$na['na'];
header('Location: ok.php');
echo 'hi';
?>

error_log:
PHP Notice:  Undefined variable:  na in /www/mysite/htdocs/problem.php on line 2
PHP Warning:  Cannot modify header information - headers already sent in /www/mysite/htdocs/problem.php on line 3

configure options:
./configure \
        --with-config-file-path=/svr/php-cgi \
        --prefix=/svr/php-cgi \
        --enable-force-cgi-redirect \
        --disable-cli \
        --enable-bcmath \
        --enable-trans-sid \
        --with-zlib-dir=/build/zlib-1.1.4 \
        --with-gd=/build/gd-1.8.4 \
        --with-png-dir=/build/png-1.2.4 \
        --with-jpeg-dir=/build/jpeg-6b \
        --with-freetype \
        --with-mysql=/usr/local \
        --with-gettext \
        --with-imap \
        --with-imap-ssl \
        --with-kerberos \

php.ini, relevant options:
error_reporting E_ALL
output_buffering On
log_errors on
display_errors off

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-05 15:40 UTC] msopacua@php.net
This isn't the source of 'problem.php' as the 'header already sent' points to line 3, which is the header command itself. It never points to the header line itself.

Please include post script, so that the correct line is reported.

Also -> this is bound to fail, as line 4 outputs stuff. The header function != redirect. You should call exit after after the header command.

I'm leaving this open, since user reports it works in the module version.
 [2003-02-05 16:25 UTC] zlo at canada dot com
>This isn't the source of 'problem.php'
But it is! the messages and source code are exactly that!
http://docs.ndg.ru/p1.php
this one works as intended (in all versions) - redirects to ok.php
<?php
#$res=$na['na'];
header('Location: ok.php');
echo 'hi';
?>
this one fails in cgi versions and produces those error messages in error_log:
http://docs.ndg.ru/p2.php
<?php
$res=$na['na'];
header('Location: ok.php');
echo 'hi';
?>

also, see the http "conversation":

GET /p1.php HTTP/1.1
HOST: docs.ndg.ru

HTTP/1.1 302
Date: Wed, 05 Feb 2003 22:05:10 GMT
Server: Apache/1.3.27 (Unix) PHP/4.3.0
X-Powered-By: PHP/4.3.1-dev
Location: ok.php
Transfer-Encoding: chunked
Content-Type: text/html; charset=windows-1251

2
hi
0

GET /p2.php HTTP/1.1
HOST: docs.ndg.ru

HTTP/1.1 200 OK
Date: Wed, 05 Feb 2003 22:05:39 GMT
Server: Apache/1.3.27 (Unix) PHP/4.3.0
X-Powered-By: PHP/4.3.1-dev
Transfer-Encoding: chunked
Content-Type: text/html; charset=windows-1251

2
hi
0

==
my point is, regardless of whether outputting anything after header('Location: xxx') is correct or not (in fact if i comment out the last line, the behaviour is exactly the same), this effect is IMHO undesired and illogical.
 [2003-02-05 17:26 UTC] zlo at canada dot com
I have an idea why that might be the case.
By default, errors/warnings/notices are logged to stderr.
When run from console, it is displayed. PHP therefore considers it "output", produces headers and the subsequent attempts to use header() fail.
When used in such cgi mode, stderr is redirected to apache's error_log, but PHP does not suspect that and behaves as if the first NOTICE was sent to the output.

directing PHP's error_log to a file from php.ini solves this problem.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 05:01:30 2024 UTC