Page 1 of 1

session_start - headers already sent - really messed up!

Posted: Tue Sep 09, 2008 7:09 am
by [UW] Jake
Okay so here's the deal. I have a file called test.php

For testing purposes I've made its content

Code: Select all

<?php
session_start();
?>
Hi
I get this error

Code: Select all

 
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/ilytorg/public_html/layouts/test.php:1) in /home/ilytorg/public_html/layouts/test.php on line 10
However, if I put the same EXACT code in 'ah.php', in the same directory, and open that file, it acts how it's supposed to. I'm SO confused why it's doing this! It's like file-specific on which files can open a session and which can't. Even if they're the same exact file, with the same permissions, just a different name.

What is this bug??

Re: session_start - headers already sent - really messed up!

Posted: Tue Sep 09, 2008 7:16 am
by marcth
Under what character-set is the file saved under? Somewhere before you call session_start(), you're code is outputting content to the screen. It may even be a white-space character like

Code: Select all

 
 
<?php // ^White space above
session_start()
?>
 
If you can't find and remove what's being outputted, you can take the lazy road an use output buffering (see ob_start and related functions).

If most of your application is relying on sessions, than declare your session_start at the beginning of your front controller or index.php.