poddys Posted October 19, 2011 Share Posted October 19, 2011 I inherited a system written in PHP where the originator was rather sloppy at coding, and where there are often errors but not consistent ones. There are so many errors in the Apache log, I want to eradicate all of them, except for the "real" ones, as I currently can't see the wood for the trees... One I have been trying to stop is where they added Session_start() at the beginning of every program, which of course generates a message if a session is already started. I know it's a warning, but I "anally" would like to create code that does not generate warnings if at all possible. What is the best way to determine if a session has already been started? I have been using: if (!isset ($_COOKIE[ini_get('session.name')])) session_start(); but this doesn't always seem to work. Thanks in advance for any help. Tony Quote Link to comment https://forums.phpfreaks.com/topic/249375-best-way-to-tell-if-session-is-started/ Share on other sites More sharing options...
SparK_BR Posted October 19, 2011 Share Posted October 19, 2011 if you exclude all session_start() calls and leave only the ones that get called directly, like the main screen, the things that get called through ajax or something. then you wouldn't need session_start() for the rest I mean, included/required files don't need session_start() other than that just check if session_id() returns an empty string Quote Link to comment https://forums.phpfreaks.com/topic/249375-best-way-to-tell-if-session-is-started/#findComment-1280466 Share on other sites More sharing options...
poddys Posted November 2, 2011 Author Share Posted November 2, 2011 Thanks. Sorry for the delay in responding. That helped and is what I have ended up doing. It works well. Quote Link to comment https://forums.phpfreaks.com/topic/249375-best-way-to-tell-if-session-is-started/#findComment-1284224 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.