Home > Article > Backend Development > PHP remembers password PHP uses cookies to implement the function of remembering passwords
This article introduces an example of code that uses cookies to remember passwords in PHP. Friends in need can refer to it.
The login page is obtained using jquery.cookie.js, and the password is md5 encrypted. While encrypting, a security code is also set, adding a character before the user's password. Another way I thought of was to add version information to the cookie. By judging the version information, it can be solved that users who have remembered the password before can also log in by entering it. The following is the process of cookie encoding and decoding. It is very simple and is for your reference. Code: <?php //cookie编码过程 function encodecookie($txt){ $key = C('KEY_COOKIE'); for($i = 0; $i < strlen($txt); $i++){ $txt[$i] = chr(ord($txt[$i]) + $key); } return $txt = urlencode(base64_encode(urlencode($txt))); } //ookie解码过程c function decodecookie($txt){ $key = C('KEY_COOKIE'); $txt = urldecode(base64_decode($txt)); for($i = 0; $i<strlen($txt); $i++){ $txt[$i] = chr(ord($txt[$i]) - $key); } return $txt; } ?> The example is very small. It only provides an implementation idea. I hope it can help everyone. |