CodeIgniter Forums
how to create a remeber me tickbox on sign in of user - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: how to create a remeber me tickbox on sign in of user (/thread-53313.html)



how to create a remeber me tickbox on sign in of user - El Forum - 07-18-2012

[eluser]dhananjay[/eluser]
i want to create a remember me when a user sign in on website so next time he visits i can get his login information from his browser and auto fill them.....




how to create a remeber me tickbox on sign in of user - El Forum - 07-19-2012

[eluser]InsiteFX[/eluser]
1) Add the checkbox to your form.
2) Check to see if the user has checked it.
3) If so generate a random hash code and save it to the users database record.
4) Create and write out a cookie called rememberme with the hash code value.
5) Check to see if they have the cookie when they come back to your web site.
6) Get the cookie.
7) If they do have the cookie use the hash code to find the record in the database.
8) Auto log the user in.



how to create a remeber me tickbox on sign in of user - El Forum - 07-23-2012

[eluser]dhananjay[/eluser]
when user make login

i m checking if he has checked remember me checkbox
if he has checked i m generating a hash and setting it in his browser
no when any visit login page i am checking for that cookie if cookie has been set i m geeting that hash code if matched makin that user login

now i want to ask how two users can use remeber me from same browser?

if cookie has been set as he move to that login page he is made logged in....


how to create a remeber me tickbox on sign in of user - El Forum - 07-24-2012

[eluser]InsiteFX[/eluser]
To stop that from happening store the users ip address in the database record and check it also on login.

This will make sure the the user can only login from one machine.



how to create a remeber me tickbox on sign in of user - El Forum - 07-24-2012

[eluser]dhananjay[/eluser]
i dont think that will work you cant get ip adress of system of user if they are accessing through same ip adress like a network or modem they all will have same ip address...


how to create a remeber me tickbox on sign in of user - El Forum - 07-24-2012

[eluser]InsiteFX[/eluser]
Then add a unique id to the cookie and check that.




how to create a remeber me tickbox on sign in of user - El Forum - 07-24-2012

[eluser]dhananjay[/eluser]
lets i added a unique id for that user ,
now how i will get that cookie and check.....


how to create a remeber me tickbox on sign in of user - El Forum - 07-24-2012

[eluser]InsiteFX[/eluser]
The same way, if you take an associated array and serialize it it will then be a string that you can store in the cookie.
Code:
$data = array(
    'id'        => $id,
    'unique_id' => $unique_id
);

$value = serialize($data);

set_cookie('cookie_name', $value, etc);

$data = unserialize(get_cookie('cookie_name'));



how to create a remeber me tickbox on sign in of user - El Forum - 07-24-2012

[eluser]dhananjay[/eluser]
if i will use this so if a user has remembered and i have set cookie
if anyone using same browser to access website he will be automatically logged in by using the previous cookie saved

i thin this will work in the way as is working if a user has remembered on login any one using that browser will be logged in there is no way that it will know that now this is a different user...