monkeytooth Posted December 24, 2009 Share Posted December 24, 2009 I don't know if this is a self defeating concept or not. One of the people I am coding with added this line to the top of the index file if(!isset($_SESSION)) {session_start();} for some reason that doesn't make sense to me, would that be a self defeating way of starting a session? don't you need to have it just as session_start(); no matter what and not wrapped in a if-else? Quote Link to comment https://forums.phpfreaks.com/topic/186271-sessions-self-defeating/ Share on other sites More sharing options...
ignace Posted December 24, 2009 Share Posted December 24, 2009 In some bad designed applications people use this technique to verify wether or not session has already been started. Normally you don't check _SESSION but session_id() instead as when session's hasn't yet been started session_id() will return "" Quote Link to comment https://forums.phpfreaks.com/topic/186271-sessions-self-defeating/#findComment-983761 Share on other sites More sharing options...
monkeytooth Posted December 24, 2009 Author Share Posted December 24, 2009 Thats what I was figuring, But couldn't find anything one way or another on something similar to the effect of the line I originally gave. So I thought I would come and ask. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/186271-sessions-self-defeating/#findComment-983773 Share on other sites More sharing options...
ignace Posted December 24, 2009 Share Posted December 24, 2009 For example if your application has different sources that all may use sessions then at some point a source may rely on sessions and thus writing something like: $_SESSION['datakey'] = 'datavalue'; Now the line if (!isset($_SESSION)) { session_start(); } Evaluates false and session's does not get started the array _SESSION gets filled with data but is not persisted between requests. Quote Link to comment https://forums.phpfreaks.com/topic/186271-sessions-self-defeating/#findComment-983774 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.