Checking for PHP session without starting one?

后端 未结 3 665
感情败类
感情败类 2021-02-12 20:30

Is it possible to check for a session with out starting one?

The reason that I ask is, the app I am developing has an integrated admin interface. So when an admin is logg

3条回答
  •  花落未央
    2021-02-12 20:54

    Here's a function that will do what you ask, which is checking whether a session exists before starting it:

    function sessionExists() {
        return (isset($_COOKIE[session_name()]));
    }
    

    If you want to test for it in the same request that you created it, you can do this instead:

    function sessionExists() {
        return (isset($_SESSION) || isset($_COOKIE[session_name()]));
    }
    

提交回复
热议问题