Welcome Guest, Not a member yet? Register   Sign In
Override sess_expiration outside config file?
#1

[eluser]chadwhitaker[/eluser]
I want to be able to set the session expiration default in the config.php file (say 2 hours) but be able to override the session expiration if someone checks "remember me" on the login form.

Although when I run $this->config->set_item('sess_expiration', 64000); it will not override the $config['sess_expiration'] in the config file. How can I get around this?

Thank you
#2

[eluser]Pedro Luz[/eluser]
try commenting and then testing Tongue

Code:
//$config['sess_expiration']= 7200;

Big Grin

Code:
isset(rememberMe) ? $this->config->set_item(‘sess_expiration’, 64000) : $this->config->set_item(‘sess_expiration’, 7200)

dont know if works Tongue
#3

[eluser]InsiteFX[/eluser]
For a remember me you need to create a cookie and send it to the user client.

The cookie will have the expiration time set in it.

Otherwise if setting the config item it will overide everyone!

InsiteFX
#4

[eluser]Kraig[/eluser]
In doing this would it only override the current session, or would it use 0 until it is reset somewhere in the code back to 7200?
#5

[eluser]InsiteFX[/eluser]
If you set it to 0 CI will set the session to expire 2 years from now for all sessions.

I set the session to expire on browser close, when user logs in I check to see if they
have a Remember Me cookie if so I read the cookie and retrive the hash code and
compare with the hash code in the users table.

If they match I auto log the user back into the system.

The only item stored in the Remember Me cookie is the hash code, Which
I salt an random identifier with SHA-512 using the CI config encrpytion_key


#6

[eluser]Kraig[/eluser]
After you check the DB for that hash and it returns true...would you create a session with the user's id, or anything like that?
#7

[eluser]InsiteFX[/eluser]
You would create everything just like you were logging in the user without a Remember Me cookie.

I usually place this code in the constructor of a MY_Controller

A note about php5 and cookies, do not output anything to the screen before
writing a cookie it will fail to write it.




Theme © iAndrew 2016 - Forum software by © MyBB