This is how I accomplished the remember me feature. Since I didn't find any specific resources on this matter, the proposed solution may or may not be optimal and correct, although it works fine.
You use the following code to login a user programmatically:
$user = user_load($uid);
$login_array = array ('name' => $user_first_query->name);
After that you have to decide whether to persist the login or not using the provided check box in the login form:
//at this point we need to persist the login by saving the user again
//with the remember_me data. But doing so, resets the user picture.
//So we need to preserve it somehow.
$user_picture_id = $user->picture;
user_save($user, array('data' => array('remember_me' => (int)$_POST['remember_me'])));
//restore the user picture id
'picture' => $user_picture_id,
For the part where I have done
unset($user->data['remember_me']); I have made sure that the rememeber_me data does not exist from a previous login. I think this should be done in the
modulename_user_presave() hook but I couldn't implement it there.
Remember that since the main question is how to persist a user login, I have not provided a full login procedure, for example you should authenticate the user's credentials using the