By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,064 Members | 1,449 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,064 IT Pros & Developers. It's quick & easy.

how do I fix this " Warning: session_start(): Cannot send session cache limiter"

P: n/a
How can I find out where my script is outputting to the screen for the
first time?

My error logs are full of stuff like this:
[24-May-2006 19:51:22] PHP Warning: session_start(): Cannot send
session cache limiter - headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php
on line 14
[24-May-2006 19:51:22] PHP Warning: Cannot modify header information -
headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachineIdOnVisitorsMachine.php
on line 26
[24-May-2006 19:51:26] PHP Warning: session_start(): Cannot send
session cache limiter - headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php
on line 14
[24-May-2006 19:51:26] PHP Warning: Cannot modify header information -
headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachineIdOnVisitorsMachine.php
on line 26
[24-May-2006 19:54:42] PHP Warning: session_start(): Cannot send
session cache limiter - headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php
on line 14
[24-May-2006 19:54:42] PHP Warning: Cannot modify header information -
headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachineIdOnVisitorsMachine.php
on line 26
[24-May-2006 19:54:45] PHP Warning: session_start(): Cannot send
session cache limiter - headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php
on line 14
[24-May-2006 19:54:46] PHP Warning: Cannot modify header information -
headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachineIdOnVisitorsMachine.php
on line 26

but the lines they are pointing to are

session_start();
session_register();

May 25 '06 #1
Share this Question
Share on Google+
19 Replies


P: n/a
NC
lawrence k wrote:

How can I find out where my script is outputting to the screen
for the first time?
It may not be your script; it could be one of the files you are
including...
My error logs are full of stuff like this: .... but the lines they are pointing to are

session_start();
session_register();


You probably have a blank space or an empty line somewhere between the
beginning of a file and the first "<?"... Find it and delete it.
Alternatively, use output buffering; start buffering at the beginning
of the script and dump the buffer after you're done working with
sessions...

Cheers,
NC

May 25 '06 #2

P: n/a
In article <11**********************@38g2000cwa.googlegroups. com>,
lawrence k <lk******@geocities.com> wrote:
[24-May-2006 19:51:22] PHP Warning: Cannot modify header information -
headers already sent in


You're sending some of the body before the session is started. Don't
do that ;)

--
http://www.spinics.net/lists/php/
May 26 '06 #3

P: n/a
Actually there could be a space or blank line before any <?, after any ?>,
any html in files included in the script or even a header statement prior to
the session start statement. You can try starting the session at the
begining of the file and then moving it back to where you had it until you
find the offending code.

Just remember the session start has to be done prior to any output being
sent.

James
May 26 '06 #4

P: n/a
you must place the header() function ontop of everything in the code.
if your trying to redirect use javascript.

May 28 '06 #5

P: n/a

Someuser wrote:
Actually there could be a space or blank line before any <?, after any ?>,
any html in files included in the script or even a header statement prior to
the session start statement. You can try starting the session at the
begining of the file and then moving it back to where you had it until you
find the offending code.
Just remember the session start has to be done prior to any output being
sent.


I know that. My question was how do I find out where the output
starts? My system has 1800 PHP files. I can't go through them one at a
time looking for white space..

May 31 '06 #6

P: n/a

NC wrote:
lawrence k wrote:

How can I find out where my script is outputting to the screen
for the first time?
It may not be your script; it could be one of the files you are
including...
My error logs are full of stuff like this:

...
but the lines they are pointing to are

session_start();
session_register();


You probably have a blank space or an empty line somewhere between the
beginning of a file and the first "<?"... Find it and delete it.


I know that. My question was how do I find out where the output
starts? Is there an IDE that would check this for me?

My system has 1800 PHP files. I can't go through them one at a time
looking for white space.

Alternatively, use output buffering; start buffering at the beginning
of the script and dump the buffer after you're done working with
sessions...


That would disguise the problem, but a year frow now it would probably
come back and bite me. I need to fix the true problem, not hide it.

May 31 '06 #7

P: n/a
Rik
lawrence k wrote:
My system has 1800 PHP files. I can't go through them one at a time
looking for white space.

900
450
225
123
62
31
16
8
4
2
1

That's the road to take when searching for this, 11 easy steps, unless the
problem is in more then one document. Also, a real editor could search files
for input before '<?'.

You could offcourse make PHP do the work for you:
$files = array of files included/'on your system'
Loop through the text equivalent of your files with a regular expression
like (.+)<? on the beginning of every file.

Or use ob_start()
And 1800 if(ob_get_contents()!='') echo "problem is
before".__FILE__','__LINE__;'s

And it's not a matter of "your system", it's a matter of files that are
included before the header call().
If that's indeed > 1800 files:
- I'm very curious on what bases you put code in different files, and what
the exact goal of your script actually is to include that many.
- I'd suggest a more sensible grouping then "1800 files", so you can exclude
groups (maybe fake output) of files in this kind of troubleshooting.

Grtz,
--
Rik Wasmus
Jun 1 '06 #8

P: n/a

Rik wrote:
lawrence k wrote:
My system has 1800 PHP files. I can't go through them one at a time
looking for white space.

a real editor could search files
for input before '<?'.


Good point. Homesite could do that for me, or Jedit. I appeciate the
suggeston.

Or use ob_start()
And 1800 if(ob_get_contents()!='') echo "problem is
before".__FILE__','__LINE__;'s
Thanks, that is a great idea. I'll try to rig up a test.
- I'm very curious on what bases you put code in different files, and what
the exact goal of your script actually is to include that many.
- I'd suggest a more sensible grouping then "1800 files", so you can exclude
groups (maybe fake output) of files in this kind of troubleshooting.


Every function and class is in its own file, because usually less than
300 are needed for any given project, so there is no point including
them all on every page. There is a central object that includes them
when they are needed.

Jun 1 '06 #9

P: n/a

NC wrote:
lawrence k wrote:

How can I find out where my script is outputting to the screen
for the first time?


It may not be your script; it could be one of the files you are
including...
My error logs are full of stuff like this:

...
but the lines they are pointing to are

session_start();
session_register();


You probably have a blank space or an empty line somewhere between the
beginning of a file and the first "<?"... Find it and delete it.
Alternatively, use output buffering; start buffering at the beginning
of the script and dump the buffer after you're done working with
sessions...


Well, I probably do have some open white space in the code. I did a
search for it and found at last 6 files that were leaking white space.
I fixed those 6 files. Sadly, my error logs are still full of "Warning:
session_start(): Cannot send session cache"...

I'm going crazy. I can't set sessions because my code is leaking white
space. I can't find a way to track down that white space. Surely there
is an IDE or test kit that will help me track this down?

Jun 17 '06 #10

P: n/a
lawrence k wrote:
NC wrote:
lawrence k wrote:
How can I find out where my script is outputting to the screen
for the first time?


It may not be your script; it could be one of the files you are
including...

My error logs are full of stuff like this:


...
but the lines they are pointing to are

session_start();
session_register();


You probably have a blank space or an empty line somewhere between the
beginning of a file and the first "<?"... Find it and delete it.
Alternatively, use output buffering; start buffering at the beginning
of the script and dump the buffer after you're done working with
sessions...

Well, I probably do have some open white space in the code. I did a
search for it and found at last 6 files that were leaking white space.
I fixed those 6 files. Sadly, my error logs are still full of "Warning:
session_start(): Cannot send session cache"...

I'm going crazy. I can't set sessions because my code is leaking white
space. I can't find a way to track down that white space. Surely there
is an IDE or test kit that will help me track this down?


First of all, maybe "every function and class has its own file" is a bit
overkill. I usually group things together - especially functions. Even if you
include some unused functions, so what? And you'll save the time necessary to
locate and load dozens of individual files.

Also, turn on all errors and display the errors. You'll get a message to the
effect "Output was started at line xxx in file yyy", which tells you where the
code or whitespace caused the headers to be sent.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 18 '06 #11

P: n/a

Jerry Stuckle wrote:
lawrence k wrote:
NC wrote:
lawrence k wrote:

How can I find out where my script is outputting to the screen
for the first time?

It may not be your script; it could be one of the files you are
including...
My error logs are full of stuff like this:

...

but the lines they are pointing to are

session_start();
session_register();

You probably have a blank space or an empty line somewhere between the
beginning of a file and the first "<?"... Find it and delete it.
Alternatively, use output buffering; start buffering at the beginning
of the script and dump the buffer after you're done working with
sessions...

Also, turn on all errors and display the errors. You'll get a message to the
effect "Output was started at line xxx in file yyy", which tells you where the
code or whitespace caused the headers to be sent.


I'm not sure I know what you mean when you say "turn on all errors". We
are talking about my error logs - everything is one by default. The
logs capture everything, including every notice, warning, parse error,
etc. I don't believe you can even turn that stuff off, in the logs.

But as I said earlier in the thread, PHP is giving me bum messages that
offer no illumination. My error logs are full this one line, repeated
over and over again:
[18-Jun-2006 07:56:19] PHP Warning: Cannot modify header information -
headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachineIdOnVisitorsMachine.php
on line 26
[18-Jun-2006 07:56:49] PHP Warning: Cannot modify header information -
headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachineIdOnVisitorsMachine.php
on line 26
[18-Jun-2006 12:26:19] PHP Warning: session_start(): Cannot send
session cookie - headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php
on line 14
[18-Jun-2006 12:26:19] PHP Warning: session_start(): Cannot send
session cache limiter - headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php
on line 14
[18-Jun-2006 12:59:05] PHP Warning: session_start(): Cannot send
session cookie - headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php
on line 14
[18-Jun-2006 12:59:05] PHP Warning: session_start(): Cannot send
session cache limiter - headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php
on line 14
But this is line 14 and 15 of CommandStartSession:

session_start();
session_register();

and this is line 26 of CommandSetMachineIdOnVisitorsMachine:

$success = setcookie("machineId", $machineId, time() + 10000000);
Obviously, before these two lines are called, some white space has been
sent to the browser. But PHP is not telling me where the problem
starts.

Tha is why I'm wondering if there is some IDE or test system that would
let me track down where the white space starts.

Jun 18 '06 #12

P: n/a
>> >>> session_start();
>>> session_register();
>>
>>You probably have a blank space or an empty line somewhere between the
>>beginning of a file and the first "<?"... Find it and delete it.

Unfortunately, white space and other body output isn't the only
thing that causes headers to be sent. Sending headers (e.g.
session_start()) also causes headers to be sent. If you're going
to setcookie(), setcookie() before session_start() and before any
output.

Also, don't call session_start() before session_start(). Limit:
one call per PHP hit.

session_register() should only be used if register_globals is on,
which it shouldn't be, so don't use it. Use $_SESSION.

But as I said earlier in the thread, PHP is giving me bum messages that
offer no illumination.
They are telling you where the problem is. White space is a common,
and difficult to find, but not the only cause of headers being sent.
My error logs are full this one line, repeated
over and over again:
[18-Jun-2006 07:56:19] PHP Warning: Cannot modify header information -
headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachineIdOnVisitorsMachine.php
on line 26
setcookie() goes before session_start().
[18-Jun-2006 07:56:49] PHP Warning: Cannot modify header information -
headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachineIdOnVisitorsMachine.php
on line 26
[18-Jun-2006 12:26:19] PHP Warning: session_start(): Cannot send
session cookie - headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandStartSession.php
on line 14
Don't call session_start() twice.
But this is line 14 and 15 of CommandStartSession:

session_start();
session_register();

and this is line 26 of CommandSetMachineIdOnVisitorsMachine:

$success = setcookie("machineId", $machineId, time() + 10000000);


Gordon L. Burditt
Jun 18 '06 #13

P: n/a
lawrence k wrote:
Jerry Stuckle wrote:
Also, turn on all errors and display the errors. You'll get a message to the
effect "Output was started at line xxx in file yyy", which tells you where the
code or whitespace caused the headers to be sent.

I'm not sure I know what you mean when you say "turn on all errors". We
are talking about my error logs - everything is one by default. The
logs capture everything, including every notice, warning, parse error,
etc. I don't believe you can even turn that stuff off, in the logs.


Actually, not everything is on by default. E_NOTICE defaults to off - and often
contains a lot of good information. And anything can be turned on or off in
your log. It's all in the php.ini file.
But as I said earlier in the thread, PHP is giving me bum messages that
offer no illumination. My error logs are full this one line, repeated
over and over again:


Not necessarily. Gordon gave you some good info, also. Check out his ideas.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 18 '06 #14

P: n/a

Gordon Burditt wrote:
>>> session_start();
>>> session_register();
>>
>>You probably have a blank space or an empty line somewhere between the
>>beginning of a file and the first "<?"... Find it and delete it.
Unfortunately, white space and other body output isn't the only
thing that causes headers to be sent. Sending headers (e.g.
session_start()) also causes headers to be sent. If you're going
to setcookie(), setcookie() before session_start() and before any
output.

Also, don't call session_start() before session_start(). Limit:
one call per PHP hit.
Thank you. Your advice is some of the most helpful that I've gotten.
But when I use my text editor to run a global search on all of my code,
I only find one call to session_start().
session_register() should only be used if register_globals is on,
which it shouldn't be, so don't use it. Use $_SESSION.


I've deleted the call to session_register(). I hope this helps.



My error logs are full this one line, repeated
over and over again:
[18-Jun-2006 07:56:19] PHP Warning: Cannot modify header information -
headers already sent in
/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachineIdOnVisitorsMachine.php
on line 26


setcookie() goes before session_start().


Oh! That is very good to know. Can I ask where you found that
information? This page:

http://us3.php.net/session_start

says "If a user uses ob_gzhandler or like with ob_start(), the order of
output handler is important for proper output. For example, user must
register ob_gzhandler before session start."

but from that it's not transparent to me that cookies must be called
before session_start(). Where is this stated as a general principle?

However, I'll now call setcookie before I call session_start(). Hope
that helps.

Thanks much for all your help

Jun 18 '06 #15

P: n/a

Gordon Burditt wrote:
>>> session_start();
>>> session_register();
>>
>>You probably have a blank space or an empty line somewhere between the
>>beginning of a file and the first "<?"... Find it and delete it.


Unfortunately, white space and other body output isn't the only
thing that causes headers to be sent. Sending headers (e.g.
session_start()) also causes headers to be sent. If you're going
to setcookie(), setcookie() before session_start() and before any
output.

Also, don't call session_start() before session_start(). Limit:
one call per PHP hit.

session_register() should only be used if register_globals is on,
which it shouldn't be, so don't use it. Use $_SESSION.

But as I said earlier in the thread, PHP is giving me bum messages that
offer no illumination.


They are telling you where the problem is. White space is a common,
and difficult to find, but not the only cause of headers being sent.


I think you are right, they are telling me where the problem is. I now
suspect the error was being triggered when this class method (which
sends a charset header) was called:
function command() {
// 09-02-04 - we want the server to send a header explaining that the
charset is
// UTF-8 (which the software is now going to standardize around, I
just changed
// the functions standardInput() and standardOutput() to cast all
input to UTF-8).
// How can Apache know the right charset when all the text is stored
in a MySql
// database? It seems likely to me that we need to take responsiblity
for ensuring
// that the right header is sent. This function now gets called at
the top of
// both configAdminEvents.php and configPublicEvents.php

$this->core->notes("We are at the beginning of command() in
CommandSendUtf8Header.");

if (function_exists("headers_sent")) {
$sent = headers_sent();
if (!$sent) header("Content-type:text/html;charset=UTF-8");
}
$this->core->notes("We are at the end of command() in
CommandSendUtf8Header.");
ob_end_flush();
}

Jun 18 '06 #16

P: n/a
>> >> >>> session_start();
>> >>> session_register();
>> >>
>> >>You probably have a blank space or an empty line somewhere between the
>> >>beginning of a file and the first "<?"... Find it and delete it.
Unfortunately, white space and other body output isn't the only
thing that causes headers to be sent. Sending headers (e.g.
session_start()) also causes headers to be sent. If you're going
to setcookie(), setcookie() before session_start() and before any
output.

Also, don't call session_start() before session_start(). Limit:
one call per PHP hit.


Thank you. Your advice is some of the most helpful that I've gotten.
But when I use my text editor to run a global search on all of my code,
I only find one call to session_start().


You can't do that with a text editor. You might call session_start()
once from shoot_self_in_foot() and call shoot_self_in_foot() from
several places and looping over each toe. Or you might include the
code multiple times. Execution counts. Number of mentions in the
source code doesn't. Order of execution counts. Order of mention
in the source code doesn't. Things get even messier if the function
calling session_start() is called from the constructor of a class.

I'm not real convinced that include_once() is capable of distinguishing
all possible names for the same file, and guaranteeing that it
will be included only once:
foo.php
./foo.php
././././foo.php
../dir/foo.php
bar/../foo.php
and it gets even worse with symlinks or hard links floating around.
The manual page for include_once mentions some of this problem with
respect to case-insensitive filesystems.
One of your messages seemed to be session_start() complaining about
headers already having been sent in a line you said contained
session_start(). This is why I think you are calling session_start()
more than once.

session_register() should only be used if register_globals is on,
which it shouldn't be, so don't use it. Use $_SESSION.


I've deleted the call to session_register(). I hope this helps.


This isn't likely relevant to your current problem, though.

>over and over again:
>
>
>[18-Jun-2006 07:56:19] PHP Warning: Cannot modify header information -
>headers already sent in


/home/httpd/vhosts/monkeyclaus.org/httpdocs/media/audio/pdsIncludes/CommandSetMachineIdOnVisitorsMachine.php
>on line 26


setcookie() goes before session_start().


Oh! That is very good to know. Can I ask where you found that
information? This page:

http://us3.php.net/session_start

says "If a user uses ob_gzhandler or like with ob_start(), the order of
output handler is important for proper output. For example, user must
register ob_gzhandler before session start."

but from that it's not transparent to me that cookies must be called
before session_start(). Where is this stated as a general principle?


Read the page for setcookie(). You have to call it before HTTP
headers are sent. This is a protocol limitation you're stuck with.
(And some of the details of this are obscured by output buffering).
I don't think the documentation is particularly clear on this, and
there are bits and pieces of details scattered all over.

Some things modify HTTP headers, and should only be called BEFORE headers
have been output:

setcookie() header() session_start()
session_cache_limiter() various session_*() functions
setrawcookie()
This list is by no means complete.

Some things force HTTP headers to be output if output buffering is not
in use:
session_start() Any text output
<html> <!DOCTYPE
Any white space Anything that flushes output buffering
This list is by no means complete.
The things that modify HTTP headers must come BEFORE things that force
output of HTTP headers. session_start() may only be called once.
Gordon L. Burditt
Jun 19 '06 #17

P: n/a
>> >But as I said earlier in the thread, PHP is giving me bum messages that
>offer no illumination.


They are telling you where the problem is. White space is a common,
and difficult to find, but not the only cause of headers being sent.


I think you are right, they are telling me where the problem is. I now
suspect the error was being triggered when this class method (which
sends a charset header) was called:


The combination of header(), which sends a header,
and ob_end_flush(), which forces the output, means you can't
call session_start() after this function gets called.

Gordon L. Burditt
Jun 19 '06 #18

P: n/a

Gordon Burditt wrote:
>But as I said earlier in the thread, PHP is giving me bum messages that
>offer no illumination.

They are telling you where the problem is. White space is a common,
and difficult to find, but not the only cause of headers being sent.


I think you are right, they are telling me where the problem is. I now
suspect the error was being triggered when this class method (which
sends a charset header) was called:


The combination of header(), which sends a header,
and ob_end_flush(), which forces the output, means you can't
call session_start() after this function gets called.


Thanks much. I think you found the problem. My understanding of headers
is shamefully weak. if I wanted to read up on how the headers work,
would I read up on the http protocol or the IP protocol? I'm afraid
right now I'm not even sure what category of information it is that I'm
lacking.

Jun 24 '06 #19

P: n/a
>> >> >But as I said earlier in the thread, PHP is giving me bum messages that
>> >offer no illumination.
>>
>> They are telling you where the problem is. White space is a common,
>> and difficult to find, but not the only cause of headers being sent.
>
>I think you are right, they are telling me where the problem is. I now
>suspect the error was being triggered when this class method (which
>sends a charset header) was called:
The combination of header(), which sends a header,
and ob_end_flush(), which forces the output, means you can't
call session_start() after this function gets called.


Thanks much. I think you found the problem. My understanding of headers
is shamefully weak. if I wanted to read up on how the headers work,
would I read up on the http protocol or the IP protocol?


HTTP. It's quite simple: a HTTP request consists of a request
(typically GET or POST), followed by headers (if any), followed by
a blank line, followed by a body (if any). A HTTP reply consists of
a response line, followed by headers (if any), followed by a blank
line, followed by a body (if any). You don't get to change the
order. If you've already sent the blank line, it's too late to
send more headers.
I'm afraid
right now I'm not even sure what category of information it is that I'm
lacking.


Gordon L. Burditt
Jun 25 '06 #20

This discussion thread is closed

Replies have been disabled for this discussion.