Auth::checkAuthentication PHP Method

checkAuthentication() public static method

If user is not, then he will be redirected to login page and the application is hard-stopped via exit().
public static checkAuthentication ( )
    public static function checkAuthentication()
    {
        // initialize the session (if not initialized yet)
        Session::init();
        // self::checkSessionConcurrency();
        // if user is NOT logged in...
        // (if user IS logged in the application will not run the code below and therefore just go on)
        if (!Session::userIsLoggedIn()) {
            // ... then treat user as "not logged in", destroy session, redirect to login page
            Session::destroy();
            // send the user to the login form page, but also add the current page's URI (the part after the base URL)
            // as a parameter argument, making it possible to send the user back to where he/she came from after a
            // successful login
            header('location: ' . Config::get('URL') . 'login?redirect=' . urlencode($_SERVER['REQUEST_URI']));
            // to prevent fetching views via cURL (which "ignores" the header-redirect above) we leave the application
            // the hard way, via exit(). @see https://github.com/panique/php-login/issues/453
            // this is not optimal and will be fixed in future releases
            exit;
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Construct this object by extending the basic Controller class.
  */
 public function __construct()
 {
     parent::__construct();
     // VERY IMPORTANT: All controllers/areas that should only be usable by logged-in users
     // need this line! Otherwise not-logged in users could do actions.
     Auth::checkAuthentication();
 }
All Usage Examples Of Auth::checkAuthentication