NYCPHP Meetup

NYPHP.org

[nycphp-talk] warning message on the php page

Dan Cech dcech at phpwerx.net
Wed Feb 6 10:59:56 EST 2008


Daniel Convissor wrote:
> Folks:
> 
> On Tue, Feb 05, 2008 at 08:11:24PM -0500, Dan Cech wrote:
>> chad qian wrote:
>>> Warning: session_start() [function.session-start]: Cannot send
>>> session cache limiter - headers already sent (output started at
>>> /home/getatwoq/public_html/chad/registrationverified.php:3) in
>>> /home/getatwoq/public_html/chad/inc/prehtml.php on line 23
> 
> Personally, I've been ignoring this thread.  The error message PHP 
> produces is completely clear about what and where the problem is.  But 
> Dan, who's pretty good about stuff, posted, and I was curious about what 
> drew him into the fray.  I've got to disagree with a few things he said.
> 
> 
>> The output is being started on line 23 of prehtml.php.
> 
> Actually, the error message says "output started at... 
> registrationverified.php:3."  The ":3" means line 3.  That aside,

My bad, it had been a long day.

>> Odds are fairly 
>> good that this file is 23 lines long and the end of the file looks like 
>> this:
>>
>> ?>[\n]
>>
>> That trailing newline after the closing PHP tag is causing output to 
>> start and resulting in the error message above.
> 
> Nope.  PHP is okay with one line break after the ?>, but not two.

Fair enough, the gist of the argument is that it is easy to end up with 
an additional trailing newline that isn't immediately obvious in most 
editors (I run with newline and tab marks turned on which would show 
this up) and can cause massive problems.

>> 2. End the file with a comment, like:
>>
>> // end of file[\n]
> 
> I agree it's much cleaner to not include the closing ?> at the end of the 
> file.  But putting a comment about it being the end of the file is 
> completely supurfluous.  The end of the file is the end of the file.

There are many reasons for adding a comment at the end of the file, but 
the single biggest one is to prevent the situation where some helpful 
developer looks at the file and says "Hey, they forgot a closing ?> tag 
here".  They then add the tag and maybe a couple trailing newlines for 
good measure. Hey presto, broken sessions and header redirects.

Dan



More information about the talk mailing list