Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if session has expired in Laravel 5.4

How do I check if the session has expired in laravel 5.4.

If the session has expired I want to show a message.

like image 700
Olipol Avatar asked Oct 27 '25 04:10

Olipol


2 Answers

You can use the following

if(Auth::check()) { 

}
like image 92
prola Avatar answered Oct 29 '25 18:10

prola


Laravel will Create Session For every user no matter the User is Logged in or not. It will create Token for Specific Session. You can check if the Token Exist or not.

You can check if the token is there or not by the function Session::get('_token');.

But if you are asking if You want to check if User's Session is Expired, You can use Auth::check(). It will return if the Session is Expired or not for the specific user.

For example, If the user is Logged in, It will return True or False. But you can't check if overall Session is Expired or not Because Laravel will create and Store Session For every Single Visit No Matter if the user is Authenticated or not.

Let me know if you have any More Questions or Queries regarding Laravel Sessions. Let me know if it Helps!

like image 32
p01ymath Avatar answered Oct 29 '25 18:10

p01ymath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!