Issue with Sessions! How to keep the user login forever |
Hi;
I use CI database for sessions (and user's auth). 1 - I was wondering how I can get the users to be logged in forever. 2 - Let's say user logs in and stays idle for 15 min. If I reload a page (with Ajax or Jquery) that requires the user to be logged in, it logs the user out and says the user is not logged in. How can I do it so once the user logs in, I'd be able to make ajax calls at any time without having to re login. This is my config: PHP Code: $config['sess_cookie_name'] = 'ci_session_web'; This is how I log them in: PHP Code: $newdata = array('username' => $data['member_details'][0]->first_name,'email' => $data['member_details'][0]->email, 'member_id' => $data['member_details'][0]->id, 'logged_in' => TRUE); This is how I check if the user is logged in or not. PHP Code: if(isset($this->session->userdata['logged_data']['logged_in'])) Thanks
Try this code...
Initializing data to session PHP Code: $data = array('username' => $value['username'], 'isLoggedIn' => true); checking data from session PHP Code: if($this->session->userdata('isLoggedIn')) { If you can't follow visit the documentation https://www.codeigniter.com/user_guide/l...sions.html
Hi lazyfox
Thank you for the code but how could that make a difference? it's just another way of it. I want the user to be logged in forever. I added this library, hopefully this will help: PHP Code: class MY_Session extends CI_Session { xo
so look in application/config.php and there is session expiration
the session expiration is in seconds -- so lets say for one month 60 seconds x 60 minutes x 24 hours x 31 days = 2678400 so change this PHP Code: $config['sess_expiration'] = 7200; to this for one month PHP Code: $config['sess_expiration'] = 2678400;
(12-16-2015, 12:01 PM)cartalot Wrote: so look in application/config.php and there is session expiration Still logs out!
Well, the session is only active as long as the browser window is open. Once the user closes the browser window, you have to find another way to do that. This is typically done with a cookie, and is the typical "Remember Me" functionality from logins. However, this method is full of security issues so you have to be very careful when you implement it. This discussion on Stack Overflow has good information about implementing a secure remember me.
|
Welcome Guest, Not a member yet? Register Sign In |