3

I am working with Laravel. My question is in Laravel any way to manage specific session with specific expire time.

I extends session expire time from session.php but here it's apply on all session.

For example I want to manage Login session for 1 week or specific time and other session should be expire after 1 hour or normal time like close browser.

Gautam Patadiya
  • 1,401
  • 14
  • 19
  • Possible duplicate of [How implement 'remember me' in laravel 5.1?](http://stackoverflow.com/questions/34651823/how-implement-remember-me-in-laravel-5-1) – jbe May 20 '17 at 13:05
  • @jbe thanks for your reply. It works only for login session I appreciate your reply. but "remember_token" is work for login only I also wants to use this feature for other session – Gautam Patadiya May 20 '17 at 13:08
  • How do know if the session should last 1 week or 1 hour without login? – jbe May 20 '17 at 13:18
  • that's the question sir – Gautam Patadiya May 20 '17 at 13:49
  • Unfortunately laravel uses one single session store throughout the application. There is no option to even set the expiry on the session methods. So to do something what you're asking would require to hack into the built in session store. – Sandeesh May 20 '17 at 14:34

1 Answers1

2

You could try saving date of session's assignment to user. Let's have an example of a user name.

Having mysql table session of id,user_id,session_name and created_at you could simply do something like:

$s = new Session;
$s->user_id = $user_id;
$s->session_name = 'name';

Then later on in you app you could simply check if time between NOW and $s->created_at is greater than value you are interested in (like 7 days or so). If so - delete the record and delete session by doing: session()->forget($s->session_name);

EDIT

You can also add a column of duration so you can dynamically forget sessions after time passed out.

Ethris
  • 146
  • 2
  • 13
  • Thank you for answer. for solution that you are saying I have to change my session driver to database table ? – Gautam Patadiya May 21 '17 at 04:44
  • The way I though of it was not to change it, but to create an additional table and just handle it both using session facade and database storage – Ethris May 21 '17 at 07:46