Welcome Guest, Not a member yet? Register   Sign In
Setting expire date to Session data
#1

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


#2

[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.
#3

[eluser]InsiteFX[/eluser]
You can create your encryption for your cookies to protect them if need be.
#4

[eluser]ojcarga[/eluser]
Hey Guys, isn't it true that you can set expire session time changing this?
Code:
$config['sess_expiration'] = 7200;
in the /application/config/config.php file

Sorry if I misunderstood the question :-)
#5

[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.
#6

[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;
in the /application/config/config.php file

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

[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');

//RE-SETTING THE "sess_expiration" AFTER IT SETS THE set_userdata()
$this->config->set_item('sess_expiration', 180);

Isn't this a solution? Please, correct me if i'm wrong.
#8

[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.
#9

[eluser]ojcarga[/eluser]
I didn't thought on that, even much to learn :lol:

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB