Welcome Guest, Not a member yet? Register   Sign In
how to keep the session when browser closed in codeigniter3?
#1

Currently i am using codeigniter3 which i am storing my session driver in database.
Session should not destroy on browser close.
When user clicks the logout button only then should the session get destroyed.
How to achieve it in codeigniter3?
Please give me any solutions.
This is my config file
Code:
$config['sess_driver'] = 'database';
$config['sess_use_database']    = TRUE;
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 0;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 0;
$config['sess_regenerate_destroy'] = FALSE;
In the previous version, Codeigniter had
Code:
sess_expire_on_close
in the config file but now they have removed it. https://codeigniter.com/user_guide/libra...sions.html
Reply
#2

(This post was last modified: 10-20-2015, 10:05 AM by sv3tli0.)

Just in the same file which you have put URL to there is sess_expiration description :

'The number of seconds you would like the session to last. If you would like a non-expiring session (until browser is closed) set the value to zero: 0'

Setting it to 0 means exactly that it will be valid until browser is closed.
Change it to seconds which you like for session life, usually I use some calculation as: 30 * 24 * 60 * 60 = 30 days
Best VPS Hosting : Digital Ocean
Reply
#3

In short, set the data you want remembered in a different cookie.

Lets say you want to keep a user logged in. You could store the logged in authorisation data (not session data) in a new permanent cookie. When the user comes back, he gets new session data, but your controller can then link that session to the user authorization data read from the other permanent cookie.

Personally, I do not like to do this for login info. If you shut the browser you have to log in again IMHO. It is very easy for a user to set a browser to remember usernames and passwords anyway, which they are unlikely to do on a shared or public machine, but could easily tick a 'remember me' box in such an environment by mistake, or through misunderstanding what 'remember me' does.

Hope that helps.

Paul.
Reply
#4

(10-20-2015, 10:00 AM)sv3tli0 Wrote: Just in the same file which you have put URL to there is sess_expiration description :

'The number of seconds you would like the session to last. If you would like a non-expiring session (until browser is closed) set the value to zero: 0'

Setting it to 0 means exactly that it will be valid until browser is closed.
Change it to seconds which you like for session life, usually I use some calculation as:  30 * 24 * 60 * 60 = 30 days

is it tested ? when browser close keep session if i'm not wrong this calling cookie.
Reply
#5

(10-20-2015, 06:15 PM)freddy Wrote: is it tested ? when browser close keep session if i'm not wrong this calling cookie.

Just to be clear: Setting the sess_expiration to 0 will NOT keep sessions when the browser is closed.

Quote:http://www.codeigniter.com/user_guide/li...references

The number of seconds you would like the session to last. If you would like a non-expiring session (until browser is closed) set the value to zero: 0


When a browser is closed all session data is lost. When a new session is started, you can link that session to a user id through the use of a cookie, as I described earlier. 

Data kept beyond a browser close is not session data any more. If you want to keep data beyond a browser close then you need to use something other than sessions, like persistent cookies.

I hope that helps,

Paul.

These might help too:  
http://stackoverflow.com/questions/38042...-they-work
http://stackoverflow.com/questions/12996...wser-close
Reply




Theme © iAndrew 2016 - Forum software by © MyBB