多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] * * * * * # 1 Cookie >>Cookie。在客户端存储会话信息。 ### Cookie::init() >>Cookie初始化操作 ~~~ public static function init(array $config = []) { if (empty($config)) { $config = Config::get('cookie'); } self::$config = array_merge(self::$config, array_change_key_case($config)); if (!empty(self::$config['httponly'])) { ini_set('session.cookie_httponly', 1); } self::$init = true; } ~~~ >初始化启动Cookie # 2 Cookie操作 ## 2-1 前缀操作 ### Cookie::prefix() >>设置当前cookie存储名称前缀 ~~~ public static function init(array $config = []) { if (empty($config)) { $config = Config::get('cookie'); } self::$config = array_merge(self::$config, array_change_key_case($config)); if (!empty(self::$config['httponly'])) { ini_set('session.cookie_httponly', 1); } self::$init = true; } ~~~ ## 2-2 数据操作 ### Cookie::set() >>存储数据到cookie ~~~ public static function init(array $config = []) { if (empty($config)) { $config = Config::get('cookie'); } self::$config = array_merge(self::$config, array_change_key_case($config)); if (!empty(self::$config['httponly'])) { ini_set('session.cookie_httponly', 1); } self::$init = true; } ~~~ ### Cookie::get() ~~~ 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; } } ~~~ ### Cookie::has() >>检查Cookie值 ~~~ 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]); } ~~~ ### Cookie::Delete() >>删除Cookie值 ~~~ public static function delete($name, $prefix = null) { !isset(self::$init) && self::init(); $config = self::$config; $prefix = !is_null($prefix) ? $prefix : $config['prefix']; $name = $prefix . $name; if ($config['setcookie']) { setcookie($name, '', $_SERVER['REQUEST_TIME'] - 3600, $config['path'], $config['domain'], $config['secure'], $config['httponly']); } // 删除指定cookie unset($_COOKIE[$name]); } ~~~ ### Cookie::clear() >>清空Cookie ~~~ public static function delete($name, $prefix = null) { !isset(self::$init) && self::init(); $config = self::$config; $prefix = !is_null($prefix) ? $prefix : $config['prefix']; $name = $prefix . $name; if ($config['setcookie']) { setcookie($name, '', $_SERVER['REQUEST_TIME'] - 3600, $config['path'], $config['domain'], $config['secure'], $config['httponly']); } // 删除指定cookie unset($_COOKIE[$name]); } ~~~