Home » Php » php – Differentiate session timeout in codeigniter

php – Differentiate session timeout in codeigniter

Posted by: admin July 12, 2020 Leave a comment

Questions:

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
How to&Answers:

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.

Answer:

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).