anujgarg Posted October 21, 2009 Share Posted October 21, 2009 Hi, I am getting above said error. I have tried the following but no use: if(!isset($_SESSION)) { } else { session_start(); } and if(!isset(session_id())) { } else { session_start(); } Please help... TIA Anuj Garg Quote Link to comment https://forums.phpfreaks.com/topic/178446-a-session-had-already-been-started-ignoring-session_start/ Share on other sites More sharing options...
Bricktop Posted October 21, 2009 Share Posted October 21, 2009 Hi anujgarg, This error normally appears if you are including the same file multiple times on a page, or if a file you're including also has a session_start() statement in it. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/178446-a-session-had-already-been-started-ignoring-session_start/#findComment-941015 Share on other sites More sharing options...
anujgarg Posted October 21, 2009 Author Share Posted October 21, 2009 Bricktop, to be descriptive, I am using CodeIgniter and have the statement session_start() at the bottom of the file config.php. Yes, you are right, this file is being included multiple times on a page. Please let me know what is the solution to get rid of this error. TIA Anuj Quote Link to comment https://forums.phpfreaks.com/topic/178446-a-session-had-already-been-started-ignoring-session_start/#findComment-941018 Share on other sites More sharing options...
Bricktop Posted October 21, 2009 Share Posted October 21, 2009 Hi anujgarg, You could simply use @session_start(), the @ would suppress the error but obviously there is still an error occuring and this isn't ideal. if(!isset($_SESSION)) is the correct syntax to use when checking if a session has been started. Try amending the code in your config.php to be: if(!isset($_SESSION)) { session_start(); } Then the session will only start if it hasn't already been started. Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/178446-a-session-had-already-been-started-ignoring-session_start/#findComment-941019 Share on other sites More sharing options...
dreamwest Posted October 21, 2009 Share Posted October 21, 2009 Remember to use die(); and echo when debugging a script, youll locate the error 10 times as fast if(!isset($_SESSION)){ session_start(); } echo session_id(); die(); //rest of script below.... Quote Link to comment https://forums.phpfreaks.com/topic/178446-a-session-had-already-been-started-ignoring-session_start/#findComment-941021 Share on other sites More sharing options...
anujgarg Posted October 21, 2009 Author Share Posted October 21, 2009 Thanks Bricktop, @ worked for me.. Quote Link to comment https://forums.phpfreaks.com/topic/178446-a-session-had-already-been-started-ignoring-session_start/#findComment-941026 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.