Setting expire date to Session data |
[eluser]xerosis[/eluser]
Hi, I have set the session for users to stay for 2 hours. But here is my problem, I create a custom session data: Code: $this->session->set_userdata('some_name', 'some_value'); I want this to only be active for 3 minutes and then get expired. Is it possible to assign it in the above code rather than having to do a manual check with time(); and deleting it if it is over 3 minutes every time he/she opens/refresh the page? Thanks.
[eluser]Stefan Hueg[/eluser]
You will either have to extend the Session library by a large amount or set a cookie yourself. But keep in mind: Standard cookies without a database backend can just contain 4 KB of data. http://php.net/manual/de/function.setcookie.php In case that the information in your cookie is not security critical, this should be sufficient.
[eluser]InsiteFX[/eluser]
You can create your encryption for your cookies to protect them if need be.
[eluser]ojcarga[/eluser]
Hey Guys, isn't it true that you can set expire session time changing this? Code: $config['sess_expiration'] = 7200; Sorry if I misunderstood the question :-)
[eluser]CroNiX[/eluser]
You could always just put a timestamp and store it in the session with the other data, and when you retrieve it check to see that it is less than 3 minutes old. If older, remove it, if not, use it.
[eluser]CroNiX[/eluser]
[quote author="ojcarga" date="1336498461"]Hey Guys, isn't it true that you can set expire session time changing this? Code: $config['sess_expiration'] = 7200; Sorry if I misunderstood the question :-)[/quote] Yes, but that is a global setting. If you have a special case where it needs to be lower for one instance, you don't have a way to change it.
[eluser]ojcarga[/eluser]
Thanks for the explanation, I didn't understand the first time I read the question. Doing this Code: $this->session->set_userdata('some_name', 'some_value'); Isn't this a solution? Please, correct me if i'm wrong.
[eluser]CroNiX[/eluser]
No because on the very next page load it will go back to what is set in the config, undoing anything you dynamically set.
[eluser]ojcarga[/eluser]
I didn't thought on that, even much to learn :lol: Thanks |
Welcome Guest, Not a member yet? Register Sign In |