How to check if a user is logged-in in php?

后端 未结 9 1603
南方客
南方客 2020-12-02 05:21

I\'m pretty new to php and I am trying to figure out how to use sessions to check and see if a user is logged into a website so that they would have authorization to access

9条回答
  •  情歌与酒
    2020-12-02 05:52

    Need on all pages before you check for current sessions

    session_start();
    

    Check if $_SESSION["loggedIn"] (is not) true - If not, redirect them to login page.

        if($_SESSION["loggedIn"] != true){
           echo 'not logged in';
           header("Location: login.php");
           exit;
        }
    

提交回复
热议问题