think\Cookie::get PHP Method

get() public static method

Cookie获取
public static get ( string $name, string | null $prefix = null ) : mixed
$name string cookie名称
$prefix string | null cookie前缀
return mixed
    public static function get($name, $prefix = null)
    {
        !isset(self::$init) && self::init();
        $prefix = !is_null($prefix) ? $prefix : self::$config['prefix'];
        $name = $prefix . $name;
        if (isset($_COOKIE[$name])) {
            $value = $_COOKIE[$name];
            if (0 === strpos($value, 'think:')) {
                $value = substr($value, 6);
                $value = json_decode($value, true);
                array_walk_recursive($value, 'self::jsonFormatProtect', 'decode');
            }
            return $value;
        } else {
            return null;
        }
    }

Usage Example

Example #1
0
File: Klsf.php Project: klsf/kldns
 /**
  * 获取登录用户信息
  */
 protected function getLoginuUser()
 {
     $userSid = Cookie::get("userSid");
     if (!empty($userSid)) {
         $this->userInfo = $this->pdo->find("select * from pre_users where sid=:sid limit 1", array(":sid" => $userSid));
     }
     $this->assign("userInfo", $this->userInfo);
 }
All Usage Examples Of think\Cookie::get