search
Homephp教程PHP源码PHP remember password function implementation example

PHP remember password function implementation example

May 18, 2018 am 09:52 AM
infonamenbspphone

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;
}

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools