Check PHP Session Exists

Posted Under: PHP, Programming, Tutorials on Jun 19, 2017
In PHP, to access session variable stored in $_SESSION array the page must have session_start() method invoked earlier, but when it is called multiple called, it throws PHP Notice "session already started".

To remove this Notice we need to check weather a session is already started or we should start a new one. For PHP version less than 5.4.0 following code should be used.
if(session_id() == '') {
    // initiate the session.
For newer version of PHP i.e. 5.4.0 and above, following procedure is recommended to check session initialization.
if (session_status() == PHP_SESSION_NONE) {
    // There is no session, start a new one.
© Tutorial Jinni