Hello,
You are using a checkbox in the login form for the visitor to opt for remembering login. Isn't it ? Let chk_remember be the name of that checkbox. The following PHP code will set cookie.
if(isset($HTTP_POST_VARS["chk_remember"]) && strtolower($HTTP_POST_VARS["chk_remember"])=="on")
{
setcookie("user", $arr_login_details["username"], time()+365*24*60*60);
setcookie("pass", func_encrypt($arr_login_details["password"]), time()+365*24*60*60);
}
In the above code, $arr_login_details["username"] gives the login name (username) and $arr_login_details["password"] gives the password.
func_encrypt is a function to encrypt password. You may use some simple shifting algorithms to encrypt password. (I am not going into the details of encryption).
To retrieve the username and password in login from, you can use the following PHP code.
$str_username = isset($HTTP_COOKIE_VARS["user"]) ? $HTTP_COOKIE_VARS["user"] : "";
$str_password = isset($HTTP_COOKIE_VARS["pass"]) ? func_decrypt($HTTP_COOKIE_VARS["pass"]) : "";
where func_decrypt is the reverse function of func_encrypt. This function will decrypt the password encrypted by func_encrypt.
Hope this is enough.
Best of luck.
|