Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differentiate session timeout in codeigniter

Is is possible to have two user data to have different timeout/expiry time? Let say first data "param_1" expired in 1 day and "param_2" expired in a month. How to do that with CI session library. Something that might be like this

$this->session->set_userdata('param_1', 86400);  // seconds in a day
$this->session->set_userdata('param_2', 2592000); // seconds in a month
like image 733
Va1iant Avatar asked Oct 31 '17 03:10

Va1iant


2 Answers

This would only be possible if you set a cookie on the client on a different domain than the normal one with a longer expiration date and verifying that instead of session data. In more practical terms, using an ajax .get on the page to a specific url that verifies both cookies without starting the session (since the session can already be expired).

like image 32
DevionNL Avatar answered Sep 23 '22 20:09

DevionNL


This is possible via "Tempdata":

$this->session->tempdata($key, $value, $validForTime);

However, a single session should not last more than a few hours to maybe a day. If you want some variable to persist for longer than that, sessions are absolutely the wrong tool to use for that.

like image 150
Narf Avatar answered Sep 26 '22 20:09

Narf