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(). Link to comment https://forums.phpfreaks.com/topic/108940-session_start-error/ 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 Link to comment https://forums.phpfreaks.com/topic/108940-session_start-error/#findComment-558920 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"); ... ?> Link to comment https://forums.phpfreaks.com/topic/108940-session_start-error/#findComment-558922 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. Link to comment https://forums.phpfreaks.com/topic/108940-session_start-error/#findComment-558924 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 Link to comment https://forums.phpfreaks.com/topic/108940-session_start-error/#findComment-558931 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? Link to comment https://forums.phpfreaks.com/topic/108940-session_start-error/#findComment-558934 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. Link to comment https://forums.phpfreaks.com/topic/108940-session_start-error/#findComment-558936 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 Link to comment https://forums.phpfreaks.com/topic/108940-session_start-error/#findComment-558943 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. Link to comment https://forums.phpfreaks.com/topic/108940-session_start-error/#findComment-558944 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. Link to comment https://forums.phpfreaks.com/topic/108940-session_start-error/#findComment-558949 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.