Provides two built-in methods that can be used directly in the project, which is convenient
/**
* Remember password/clear password
*
* @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 * 7, '/', ', ', true);
}else{
Setcookie ($name, ', Time ()-3600 *, '/', ', ', true);
}
}
/**
* Get the saved password
* @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;
}