PHP remembers password PHP uses cookies to implement the function of remembering passwords

WBOY
Release: 2016-07-25 08:57:25
Original
1115 people have browsed it
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;
}
?>
Copy after login

The example is very small. It only provides an implementation idea. I hope it can help everyone.



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!