You are here: Re: how do I fix this " Warning: session_start(): Cannot send session cache limiter" « PHP Programming Language « IT news, forums, messages
Re: how do I fix this " Warning: session_start(): Cannot send session cache limiter"

Posted by Gordon Burditt on 06/19/06 00:53

>> >> >>> 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация