How to create “remember me checkbox” using Codeigniter session library?

If the remember me checkbox is checked you set a cookie on the user's system with a random string. E.g. : $cookie = array( 'name' => 'remember_me_token', 'value' => 'Random string', 'expire' => '1209600', // Two weeks 'domain' => '.

Your_domain. Com', 'path' => '/' ); set_cookie($cookie) You also save this random string in the users table, e.g. In the column remember_me_token Now, when a user (who is not yet logged in) tries to access a page that requires authentication: you check if there is a cookie by the name of remember_me token on his system if it's there, you check the database if there is a record with the same value if so, you recreate this user's session (this means they are logged in) show the page they were visiting If one of the requirements above is not met, you redirect them to the login page For security reasons you may want to renew the random remember_me_token every time the user logs in. You can also update the expiry date of the cookie every time the user logs in.

This way he will stay logged in It would be too much work to write all the code for you, but I hope this helps you to implement this functionality yourself. Please comment if you have any questions. Good luck.

If the remember me checkbox is checked you set a cookie on the user's system with a random string. E.g. : $cookie = array( 'name' => 'remember_me_token', 'value' => 'Random string', 'expire' => '1209600', // Two weeks 'domain' => '.

Your_domain. Com', 'path' => '/' ); set_cookie($cookie); You also save this random string in the users table, e.g. In the column remember_me_token. Now, when a user (who is not yet logged in) tries to access a page that requires authentication: you check if there is a cookie by the name of remember_me token on his system if it's there, you check the database if there is a record with the same value if so, you recreate this user's session (this means they are logged in) show the page they were visiting If one of the requirements above is not met, you redirect them to the login page.

For security reasons you may want to renew the random remember_me_token every time the user logs in. You can also update the expiry date of the cookie every time the user logs in. This way he will stay logged in.

It would be too much work to write all the code for you, but I hope this helps you to implement this functionality yourself. Please comment if you have any questions. Good luck.

You can set sess_expiration to 0 and then set a custom variable into the session like, remember_me=1. Check this value and destroy the session if needed after a time. This would be a workarround.

I needed the same thing. You cannot accomplish this using CI settings so I have chosen to override the setcookie method of the CI Session class (in MY_Session): function _set_cookie($cookie_data = NULL) { if (is_null($cookie_data)) { $cookie_data = $this->userdata; } // Serialize the userdata for the cookie $cookie_data = $this->_serialize($cookie_data); if ($this->sess_encrypt_cookie == TRUE) { $cookie_data = $this->CI->encrypt->encode($cookie_data); } else { // if encryption is not used, we provide an md5 hash to prevent userside tampering $cookie_data = $cookie_data. Md5($cookie_data.

$this->encryption_key); } setcookie( $this->sess_cookie_name, $cookie_data, $this->userdata('rememberme') == true? $this->sess_expiration + time() : 0, $this->cookie_path, $this->cookie_domain, 0 ); } Of course you need to set the rememberme flag in your session based upon the choice the user made.

If the remember me checkbox is checked you set a cookie on the user's system with a random string. You also save this random string in the users table, e.g. In the column remember_me_token. If one of the requirements above is not met, you redirect them to the login page.

For security reasons you may want to renew the random remember_me_token every time the user logs in. You can also update the expiry date of the cookie every time the user logs in. This way he will stay logged in.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions