使用Angular和PHP进行用户身份验证

I am quite inexperienced when it comes to the topic of server-side user authentication.

I want to use as few PHP code as possible to achieve the following:

A user can log in to my app. If he does so, i will store all of that users information, including the status of being authenticated to an Angular service.

As a user navigates through my app, i need to check whether or not he is logged in. If he ain't, i need to redirect him immediately.

The question

Would it be enough to set up two session variables when the user has been logged in successfully and then doing something like this on every route change, updating my service and handle the result client-side?

public function getLogStatus(){
    return 
      $_SESSION["isLoggedIn"] == "true" &&
      $_SESSION['useradr'] == $_SERVER['REMOTE_ADDR'] ? 
        true : false;
}

Yes it IS enough.

But I suggest this :

public function checkAuth(){
   if(!$_SESSION["isLoggedIn"] || $_SESSION['useradr'] !=$_SERVER['REMOTE_ADDR'])
   header('location:"thePage.php"');
}

and call it in the first line of every method that you dont want to non-authed visitors can gain .

public function method(){

$this->checkAuth();
...
}