XpertWorlock Posted September 9, 2008 Share Posted September 9, 2008 Hi, I'm getting this error, Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /******************************) in ********************************** on line 4 with this file <?php SESSION_START(); include '../siteLayout.php'; dbConnect(); $result = mysql_query("SELECT * FROM users WHERE userName ='test'"); $num_rows = mysql_num_rows($result); echo "$num_rows Rows\n"; ?> Link to comment https://forums.phpfreaks.com/topic/123362-session-error-when-there-shouldnt-be-one-short-file/ Share on other sites More sharing options...
DarkWater Posted September 9, 2008 Share Posted September 9, 2008 Are you saving this file in UTF-8? If you are, make sure to turn off the BOM (Byte Order Mark) that some editors put in there at the beginning of the file. These get send out as output before you can send headers, so your script fails. Link to comment https://forums.phpfreaks.com/topic/123362-session-error-when-there-shouldnt-be-one-short-file/#findComment-637154 Share on other sites More sharing options...
XpertWorlock Posted September 9, 2008 Author Share Posted September 9, 2008 How would I find this out, this file is automatically created using PHP scripts, so I have no idea how it is saving it. Link to comment https://forums.phpfreaks.com/topic/123362-session-error-when-there-shouldnt-be-one-short-file/#findComment-637227 Share on other sites More sharing options...
lanmonkey Posted September 9, 2008 Share Posted September 9, 2008 try using notepad2 (http://www.flos-freeware.ch/notepad2.html) you can specify what format to save files in. also make sure there is no output being sent to the browser becore the session_start(); function is called. even a single space or linebreak will give you an error. Link to comment https://forums.phpfreaks.com/topic/123362-session-error-when-there-shouldnt-be-one-short-file/#findComment-637338 Share on other sites More sharing options...
redarrow Posted September 9, 2008 Share Posted September 9, 2008 <?php ob_start(); session_start(); include '../siteLayout.php'; dbConnect(); $result = mysql_query("SELECT * FROM users WHERE userName ='test'"); $num_rows = mysql_num_rows($result); echo "$num_rows Rows\n"; ob_flush_end(); ?> Link to comment https://forums.phpfreaks.com/topic/123362-session-error-when-there-shouldnt-be-one-short-file/#findComment-637340 Share on other sites More sharing options...
revraz Posted September 9, 2008 Share Posted September 9, 2008 ob_start is not the way to fix this problem, it's just a way to go around it. Use notepad, strip out the plain text before your session_start and it will be fixed. Link to comment https://forums.phpfreaks.com/topic/123362-session-error-when-there-shouldnt-be-one-short-file/#findComment-637432 Share on other sites More sharing options...
PFMaBiSmAd Posted September 9, 2008 Share Posted September 9, 2008 If you would post the most important part of the error message, where the output is started at that is preventing the headers from being sent, someone could directly help you with what is causing the problem. You either have white space (space, tab, newline) or BOM characters before the <?php tag. Repost your error message, xxxxxx out your path information, but leave the file names and the :x number telling where the output is occurring. And since the session_start() is the first php statement in the file, the error means that something is being output before the <?php tag and an ob_start() statement in the code will have no effect. As always, it is better to find and fix problems than to try and fix symptoms. Link to comment https://forums.phpfreaks.com/topic/123362-session-error-when-there-shouldnt-be-one-short-file/#findComment-637450 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.