php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11213 error_log() call causes warning "Cannot send session cache..."
Submitted: 2001-05-31 09:53 UTC Modified: 2001-05-31 12:58 UTC
From: uw at netuse dot de Assigned:
Status: Closed Package: Session related
PHP Version: 4.0.5 OS: SunOS 5.7
Private report: No CVE-ID: None
 [2001-05-31 09:53 UTC] uw at netuse dot de
To debug my latest PHPLib commits I needed
some output before session_start() without sending
any headers to the browser. Well, I thought of using 
error_log() that should not output anything but write 
to my logfile. I changed my php.ini to: 

display_errors = Off    
log_errors     = On    
error_log      = [mypath]/logs/

Now I hoped that I'd be allowed to use error_log() before 
session_start(), here's a simple example:

<?php
error_log("I don't like that!");

session_start();
session_register("counter");

print ++$counter;

error_log("counter = $counter");
error_log(" ")
?>

But PHP bailed at me in the error_log:

I don't like that!
PHP Warning:  Cannot send session cookie - headers already sent in [mypath]/bug.php3 on line 4
[mypath]/bug.php3(4) : Warning - Cannot s
end session cookie - headers already sent
PHP Warning:  Cannot send session cache limiter - headers already sent in
[mypath]/bug.php3 on line 4
[mypath]/bug.php3(4) : Warning - Cannot s
end session cache limiter - headers already sent
counter = 1 

Hmm, did I forget a auto_prepend file, could I be doing any output before session_start()? Let's check the results of a command line telnet request.

HTTP/1.1 200 OK
Date: Thu, 31 May 2001 13:38:27 GMT
Server: Apache/1.3.14 (Unix) PHP/4.0.5-dev mod_ssl/2.7.1 OpenSSL/0.9.5a
X-Powered-By: PHP/4.0.5
Connection: close
Content-Type: text/html

1Connection closed by foreign host.

No, I did not output anything before session_start(). Then I uncommented the first error_log() call and everything was just fine. The error log showed:

counter = 1

counter = 2

... 

The problem is the same with 4.0.4pl1 (as one could expect).

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-31 12:58 UTC] sniper@php.net
Can't reproduce with PHP 4.0.6. 

--Jani

 [2003-04-14 05:21 UTC] sumairi at hotmail dot com
I have the same problemwith PHP4.3.1, i don't include/require any files before calling session_start(). I get this error even with a test PHP file with one line having only "session_start()".

I found out that this is because the PHP file is saved with UTF-8 encoding, i tried to save it with different encodings (using Windows Notepad). Only when I save the file with ANSI encoding it will work.

This is different than "Content-Type" header. Go to Notepad open any txt file, and click file/save as.., see the encoding option.
 [2004-05-12 08:49 UTC] ckathir_nkl at yahoo dot co dot in
Warning: session_start(): Cannot send session cookie - headers already sent by (output started at d:\web\shopcart_new\echopay.php:6) in d:\web\shopcart_new\echopay.php on line 10

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at d:\web\shopcart_new\echopay.php:6) in d:\web\shopcart_new\echopay.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at d:\web\shopcart_new\echopay.php:6) in d:\web\shopcart_new\echopay.php on line 17

Warning: Cannot modify header information - headers already sent by (output started at d:\web\shopcart_new\echopay.php:6) in d:\web\shopcart_new\echopay.php on line 18
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 08:01:28 2024 UTC