diff --git a/library/think/Cookie.php b/library/think/Cookie.php index 93edb8d7..3205fcd9 100644 --- a/library/think/Cookie.php +++ b/library/think/Cookie.php @@ -135,22 +135,35 @@ class Cookie * @param string|null $prefix cookie前缀 * @return mixed */ - public static function get($name, $prefix = null) + 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]; + $key = $prefix . $name; + + if ('' == $name) { + // 获取全部 + if ($prefix) { + $value = []; + foreach ($_COOKIE as $k => $val) { + if (0 === strpos($k, $prefix)) { + $value[$k] = $val; + } + } + } else { + $value = $_COOKIE; + } + } elseif (isset($_COOKIE[$key])) { + $value = $_COOKIE[$key]; 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; + $value = null; } + return $value; } /** diff --git a/library/think/Request.php b/library/think/Request.php index efc19c35..97599144 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -802,10 +802,12 @@ class Request public function cookie($name = '', $default = null, $filter = '') { if (empty($this->cookie)) { - $this->cookie = $_COOKIE; + $this->cookie = Cookie::get(); } if (is_array($name)) { return $this->cookie = array_merge($this->cookie, $name); + } elseif (!empty($name)) { + $name = Cookie::prefix() . $name; } return $this->input($this->cookie, $name, $default, $filter); }