46 lines
1.4 KiB
PHP
46 lines
1.4 KiB
PHP
<?php
|
|
namespace lib;
|
|
|
|
class Cookie{
|
|
/**
|
|
* 删除cookie
|
|
*
|
|
* @param string $name cookie名称*
|
|
* @param string $domain 域名
|
|
* @return boolean
|
|
*/
|
|
public static function del($name,$domain=null)
|
|
{
|
|
$domain = isset($domain) ? $domain : null;
|
|
return isset($_COOKIE[$name]) ? setcookie($name, '', time() - 86400, '/', $domain) : true;
|
|
}
|
|
/**
|
|
* 得到指定cookie的值
|
|
*
|
|
* @param string $name cookie名称*
|
|
*/
|
|
public static function get($name)
|
|
{
|
|
$cookies_en=isset($_COOKIE[$name]) ? (new Aes)->decrypt($_COOKIE[$name]) : null;
|
|
return trim($cookies_en);
|
|
}
|
|
/**
|
|
* 设置cookie
|
|
*
|
|
* @param string $name cookie名称*
|
|
* @param string $value cookie值*
|
|
* @param string $expire 过期时间
|
|
* @param string $path the path to website
|
|
* @param string $domain the domain
|
|
* @param string $secure 可选。规定是否通过安全的 HTTPS 连接来传输 cookie。
|
|
* @return boolean
|
|
*/
|
|
public static function set($name,$value,$expire=null,$path=null,$domain=null,$secure=null)
|
|
{
|
|
$value= (new Aes)->encrypt($value);
|
|
$path = isset($path) ? $path : '/';
|
|
$domain = isset($domain) ? $domain : null;
|
|
$secure = isset($secure) ? $secure : 0;
|
|
return setcookie($name, $value, $expire, $path, $domain, $secure);
|
|
}
|
|
} |