samedi 28 octobre 2017

laravel 5.1 check if a session is expired

I'm working on a laravel 5.1 application and I want to check if a user session has expired after each request, in order to redirect the user to the login page. in order to do so I have created a middleware that runs on every request, the handle function looks like this

public function handle($request, Closure $next)
{
     if(session_status() === PHP_SESSION_NONE)
     {
          return redirect()->guest('login');
     }
     return $next($request);
}

this does not seem to work correctly, because when I type 'localhost:8000' in google chrome it says 'localhost redirected you too many times', I guess it is because the session have not been started since the user is not logged in, so... is there any better way to do this checking?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire