JustinK101 Posted June 6, 2008 Share Posted June 6, 2008 I am trying to put session_start() in a global include file, so basically all my pages call a file called _requires.php simply via: require_once("_requires.php"); The very first line in _requires.php is: session_start(); It is very odd though, I getting the following error: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at _requires.php:1) in_requires.php on line 2 Any ideas why? I am not outputting anything simply calling the require_once function and that require page calls session_start(). Quote Link to comment Share on other sites More sharing options...
amites Posted June 6, 2008 Share Posted June 6, 2008 what's the code look like? there are very few mind readers on this board Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted June 6, 2008 Author Share Posted June 6, 2008 login.php which is the first file is like: <?php require_once("_requires.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ..... _requires.php is like: <?php session_start(); require_once("classes/Timer.php"); require_once("classes/DatabaseConfiguration.php"); require_once("classes/Error.php"); ... ?> Quote Link to comment Share on other sites More sharing options...
haku Posted June 6, 2008 Share Posted June 6, 2008 Delete that first blank line above the opening php tag in requires.php. That blank line sends a space to the browser, which is considered to be output to the browser. You can't call session_start after output has been sent to the browser. Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted June 6, 2008 Author Share Posted June 6, 2008 Delete that first blank line above the opening php tag in requires.php. That blank line sends a space to the browser, which is considered to be output to the browser. You can't call session_start after output has been sent to the browser. Same error: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at _requires.php:1) in _requires.php on line 1 Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted June 6, 2008 Author Share Posted June 6, 2008 I can do: @session_start(); Which basically says don't show the warning and everything appears to be working, but is this a bad idea? Quote Link to comment Share on other sites More sharing options...
haku Posted June 6, 2008 Share Posted June 6, 2008 Then you didn't do it right. It told you right in the error that the output was started in line 1 of requires.php. Line 1 was the blank line. If you deleted it, then line 1 would be the php opening tag, which would mean that no output would be being sent. Check and make sure you both saved the file, and properly uploaded it to the server (if necessary). Yes, @session_start is a bad idea. The @ sign just suppresses errors, it doesn't fix them. So the error is still there, and your sessions wont work. You should pretty much never use the @ sign. Quote Link to comment Share on other sites More sharing options...
abhikerl Posted June 6, 2008 Share Posted June 6, 2008 I got this type of error too when working on a project. After a search, I found out that start_session() must be put on the first line. for example <?php session_start(); ?> <html> ........ .... ..what ever code left must go below it. http://www.islandinfo.mu Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted June 6, 2008 Author Share Posted June 6, 2008 This is how my _requires.php file is exactly: <?php session_start(); require_once("classes/Timer.php"); require_once("classes/DatabaseConfiguration.php"); require_once("classes/Error.php"); .... ?> Nothing crazy there, still getting the error. Quote Link to comment Share on other sites More sharing options...
JustinK101 Posted June 6, 2008 Author Share Posted June 6, 2008 I feel stupid I had a space before my opening php tag, very hard to see, that was the problem. Thanks guys for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.