简体   繁体   中英

Random Cannot send session cache limiter - headers already sent

In server logs I see very often there is error

PHP Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /public_html/templates/meta.php:294) in /public_html/include/query.php on line 7

Seems obvious I got output started sooner...but

Errors gets generated only sometimes and I can't reproduce it this maybe because `session_start()' is inside of if statement.

This is the beginning of query.php

<?php
//  we are including here so that we can check user logged in or not on each and everypage  
if(!isset($_SESSION))
{
    //To make the session work across multiple domains.
    session_set_cookie_params(0, '/', '.mydomain.com');
    session_start();        
}

Everywhere query.php gets included before meta.php

meta.php is mostly html and js with few php blocks and line 294 is in middle of some js function.

But what intrigues me most is that I get this error as well for request that do not involve these two files at all.

For example

From access log

66.249.72.33 - - [19/Aug/2013:22:44:30 +0100] "GET /robots.txt HTTP/1.1" 404 7592 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; + http://www.google.com/bot.html )"

66.249.72.33 - - [19/Aug/2013:22:44:30 +0100] "GET /content_files/SPIKES%20protocol.pdf HTTP/1.1" 200 215267 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; + http://www.google.com/bot.html )"

and error log

[Mon Aug 19 22:44:30 2013] [error] [client 66.249.72.33:44269] AH01215: PHP Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /public_html/templates/meta.php:294) in /public_html/include/query.php on line 7

[Mon Aug 19 22:44:30 2013] [error] [client 66.249.72.33:44269] AH01215: PHP Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /public_html/templates/meta.php:294) in /public_html/include/query.php on line 7

As You can see at 22:44:30 google bot made 2 requests 1st for robots.txt and he got 404 as there is no robots.txt 2nd for some pdf file

In both cases there is not php code involved but I got PHP warnings for these requests.

These are no other access logs from google bot before or after these.

General structure of code is like this

<?php
if(isset($_GET['url1'])){$url1 = $_GET['url1'];}else {$url1 = "";}
if(isset($_GET['url2'])){$url2 = $_GET['url2'];}else {$url2 = "";}
require_once('include/query.php');
require_once('include/auth.php');

/* some php code */
?>

<?php include 'templates/meta.php'; ?>

//html

but error gets generated for requests that do not use query.php or meta.php at all as well, like in given example.

Typically, I find that "headers already sent" errors are actually whitespace errors. Maybe check any files that are shared between all of these pages and see if there is an extra line break or space after a closing ?> tag. Generally I try to avoid using closing PHP tags at the end of files since they are discarded by the parser anyway.

标头已发送错误主要是在用于重定向或其他内容的header函数之前发生回声或任何其他输出语句时发生的。

The problem was with custom 404 page.

For clarification I have to say that it is 5 years old website and I didn't design it just making some modifications.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM