cookie: remember me
Blogs20112011-01-01
Here is my steps to use cookie to store username/password on browser side to avoid repeat input everytime.
1. Downlod jQuery’s .cookie plugin.
2. import $.cookie function, and add the following jQuery codes in HTML file:
if( $.cookie("test[username]") && $.cookie("test[password]") ) {
$('#username').val($.cookie("test[username]"));
$('#password').val($.cookie("test[password]"));
$('input[name=rememberme]').attr('checked', true);
} else {
$('input[name=rememberme]').attr('checked', false);
}
3. add in PHP code:
function insert_login_info($username, $passwd, $uid) {
$ip = $this->getRealIpAddr();
$query = "insert into login_info(uid,ip,username,passwd,count,login_time,logout,logout_time)
values('".$uid."', '".$ip."', '".$username."',
'".$passwd."', count+1, NULL, 'N', '')
on duplicate key update
count = count+1,login_time = NULL,
logout='N', logout_time=''";
if(! mysql_query($query)) {
die ("Could not add login_info information at " . __LINE__);
}
$query = "SELECT LAST_INSERT_ID()";
$res = mysql_query($query);
$row = mysql_fetch_row($res);
print_r($row);
....
}Due to time reason, I just list the outline here. It works very well.
