think\Cookie::has PHP Method

has() public static method

判断Cookie数据
public static has ( string $name, string | null $prefix = null ) : boolean
$name string cookie名称
$prefix string | null cookie前缀
return boolean
    public static function has($name, $prefix = null)
    {
        !isset(self::$init) && self::init();
        $prefix = !is_null($prefix) ? $prefix : self::$config['prefix'];
        $name = $prefix . $name;
        return isset($_COOKIE[$name]);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Cookie管理
  * @param string|array  $name cookie名称,如果为数组表示进行cookie设置
  * @param mixed         $value cookie值
  * @param mixed         $option 参数
  * @return mixed
  */
 function cookie($name, $value = '', $option = null)
 {
     if (is_array($name)) {
         // 初始化
         Cookie::init($name);
     } elseif (is_null($name)) {
         // 清除
         Cookie::clear($value);
     } elseif ('' === $value) {
         // 获取
         return 0 === strpos($name, '?') ? Cookie::has(substr($name, 1), $option) : Cookie::get($name);
     } elseif (is_null($value)) {
         // 删除
         return Cookie::delete($name);
     } else {
         // 设置
         return Cookie::set($name, $value, $option);
     }
 }