William Jiang

JavaScript,PHP,Node,Perl,LAMP Web Developer – http://williamjxj.com; https://github.com/williamjxj?tab=repositories

cookie: remember me

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]") ) {
  $('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);

Due to time reason, I just list the outline here. It works very well.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: