How to do auto login, store the session in the browser


What I do is, I keep user ID and/or username and login hash, md5(userID + username + password) as cookies.
Upon another visit, take ID from cookie and check login hash against the same formula it was generated. If the same, login automatically.
Global
$randomSeperator = '!~!';
First Run...
$hash = md5($id . $randomSeperator . $username);
setCookie('id', $id);
setCookie('username', $username);
setCookie('hash', $hash);
Second Run...
$id/$username/$hash = $_COOKIE[][][] .... // Get all 3 cookies

if($hash == md5($id . $randomSeperator . $username) ){
// Do Autologin
}

No comments:

Post a Comment