Home > php教程 > PHP源码 > PHP remember password function implementation example

PHP remember password function implementation example

不言
Release: 2018-05-18 09:52:28
Original
4453 people have browsed it

Remember password function We will see this function when logging in on many websites. Let's take a look at an implementation method of remembering password function based on PHP. The specific example is as follows.

Provides two built-in methods that can be used directly in the project, which is very convenient

/**
* 记住密码/清空密码
*
* @param $phone
* @param $pwd
* @param $name
*/
public function SeTpassword($phone, $pwd , $name, $type){
if($type == 1) {
$data = array(
'phone' => $phone,
'pwd' => $pwd
);
$key = base64_encode(json_encode($data));
setcookie($name, $key, time() + 3600 * 24 * 7, '/', '', '', true);
}else{
setcookie($name,'' , time() - 3600 * 24 * 30, '/', '', '', true);
}
}

/**
* 得到保存的密码
* @param $name
* @return mixed
*/
public function GetPassword($name){
$info = array();
if(!isset($_COOKIE[$name])){
$data['errorCode'] = 1;
}else{
if($_COOKIE[$name] == ''){
$data['errorCode'] = 1;
}else{
$key = json_decode(base64_decode($_COOKIE[$name], true),true);
if(!is_array($key)){
$data['errorCode'] = 1;
}else{
$data['errorCode'] = 0;
$info['phone'] = $key['phone'];
$info['pwd'] = $key['pwd'];
$info['type'] = 1;
}
}
}
if($data['errorCode'] == 1){
$info['phone'] = '';
$info['pwd'] = '';
$info['type'] = 0;
}
return $info;
}
Copy after login

Related labels:
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template