<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] * * * * * ## 1 Cookie文件源代碼(thinkphp/library/think/Cookie.php) ~~~ protected static $config = [ 'prefix' => '', 'expire' => 0, 'path' => '/', 'domain' => '', 'secure' => false, 'httponly' => '', 'setcookie' => true, ]; ~~~ ~~~ public static function init(array $config = []) { self::$config = array_merge(self::$config, array_change_key_case($config)); if (!empty(self::$config['httponly'])) { ini_set('session.cookie_httponly', 1); } } ~~~ ~~~ public static function prefix($prefix = '') { if (empty($prefix)) { return self::$config['prefix']; } self::$config['prefix'] = $prefix; } ~~~ ~~~ public static function set($name, $value = '', $option = null) { if (!is_null($option)) { if (is_numeric($option)) { $option = ['expire' => $option]; } elseif (is_string($option)) { parse_str($option, $option); } $config = array_merge(self::$config, array_change_key_case($option)); } else { $config = self::$config; } $name = $config['prefix'] . $name; if (is_array($value)) { array_walk_recursive($value, 'self::jsonFormatProtect', 'encode'); $value = 'think:' . json_encode($value); } $expire = !empty($config['expire']) ? time() + intval($config['expire']) : 0; if (self::$config['setcookie']) { setcookie($name, $value, $expire, $config['path'], $config['domain'], $config['secure'], $config['httponly']); } $_COOKIE[$name] = $value; } ~~~ ~~~ public static function get($name, $prefix = null) { $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; } } ~~~ ~~~ public static function delete($name, $prefix = null) { $config = self::$config; $prefix = !is_null($prefix) ? $prefix : $config['prefix']; $name = $prefix . $name; if (self::$config['setcookie']) { setcookie($name, '', time() - 3600, $config['path'], $config['domain'], $config['secure'], $config['httponly']); } unset($_COOKIE[$name]); } ~~~ ~~~ public static function clear($prefix = null) { if (empty($_COOKIE)) { return; } $config = self::$config; $prefix = !is_null($prefix) ? $prefix : $config['prefix']; if ($prefix) { foreach ($_COOKIE as $key => $val) { if (0 === strpos($key, $prefix)) { if (self::$config['setcookie']) { setcookie($key, '', time() - 3600, $config['path'], $config['domain'], $config['secure'], $config['httponly']); } unset($_COOKIE[$key]); } } } else { unset($_COOKIE); } return; } ~~~ ~~~ private static function jsonFormatProtect(&$val, $key, $type = 'encode') { if (!empty($val) && true !== $val) { $val = 'decode' == $type ? urldecode($val) : urlencode($val); } } ~~~ ## 2 分析 1 `$config` cookie配置參數 cookie相關配參數置見基礎原理的網絡通信之cookie 2 `public static function init(array $config = []){}` cookie初始化。 3 `public static function prefix($prefix = ''){}` cookie前綴設置 4 `public static function set($name, $value = '', $option = null){}` 設置cookie的配置參數,設置cookie的$name=>$value值對 5 `public static function get($name, $prefix = null){}` 獲取cookie的$name對應的值 6 `public static function delete($name, $prefix = null){}` 刪除cookie的$name 7 `public static function clear($prefix = null){}` 清空所有cookie 8 `private static function jsonFormatProtect(&$val, $key, $type = 'encode')` 數據格式轉換,在set,get中調用 ## 3 使用方法 1 cookie快速操作 在helper.php中封裝了 cookie()方法來快速操作Cookie 與tp3.2類似,使用方法見[官方手冊](http://www.hmoore.net/manual/thinkphp/1873) ## 4 總結 2個配置操作函數:init() prefix() 4個cookie數據操作函數:set() get() delete() clear() 1個私有格式轉換函數:jsonFormatProtect() 總共6個公共可調用方法,1個私有方法。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看