From 8250a4268b1540a74188d79ef0aee13f41bcdddb Mon Sep 17 00:00:00 2001 From: oldrind Date: Thu, 10 Dec 2015 01:28:02 +0800 Subject: [PATCH 1/2] Update cookie.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit // 设置cookie if (is_array($value)) { $value = 'think:' . json_encode(array_map('urlencode', $value)); } 这里如果$value为多维数组时,代码就不能正确执行。所以建议换成array_walk_recursive函数来处理。 当$value是多维数组时,这段代码就不能正确运行。 --- library/think/cookie.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/library/think/cookie.php b/library/think/cookie.php index 6ab2a9fe..8ab69af9 100644 --- a/library/think/cookie.php +++ b/library/think/cookie.php @@ -82,7 +82,8 @@ class Cookie $name = $config['prefix'] . $name; // 设置cookie if (is_array($value)) { - $value = 'think:' . json_encode(array_map('urlencode', $value)); + array_walk_recursive($value, $this->jsonFormatProtect, 'encode'); + $value = 'think:' . json_encode($value); } $expire = !empty($config['expire']) ? time() + intval($config['expire']) : 0; setcookie($name, $value, $expire, $config['path'], $config['domain'], $config['secure'], $config['httponly']); @@ -103,10 +104,10 @@ class Cookie $value = $_COOKIE[$name]; if (0 === strpos($value, 'think:')) { $value = substr($value, 6); - return array_map('urldecode', json_decode($value, true)); - } else { - return $value; + $value = json_decode(MAGIC_QUOTES_GPC ? stripslashes($value) : $value, true); + array_walk_recursive($value, $this->jsonFormatProtect, 'decode'); } + return $value; } else { return null; } @@ -156,4 +157,12 @@ class Cookie } return; } + + private static function jsonFormatProtect(&$val, $key, $type = 'encode') + { + if (!empty($val) && true !== $val) { + $val = 'decode' == $type ? urldecode($val) : urlencode($val); + } + } + } From 6ad5a19913fbc301dd77bc325a2f8f923c9fbe0f Mon Sep 17 00:00:00 2001 From: luofei614 Date: Wed, 9 Dec 2015 23:35:09 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B9=E4=BE=BF=E4=BD=BF=E7=94=A8session?= =?UTF-8?q?=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 5 +++-- library/think/session.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/convention.php b/convention.php index 44bb97c0..5517a7f3 100644 --- a/convention.php +++ b/convention.php @@ -44,8 +44,6 @@ return [ 'default_return_type' => 'html', // 默认语言 'default_lang' => 'zh-cn', - // 是否使用session - 'use_session' => true, // 默认跳转页面对应的模板文件 'dispatch_jump_tmpl' => THINK_PATH . 'tpl/dispatch_jump.tpl', @@ -80,8 +78,11 @@ return [ 'prefix' => '', 'expire' => 0, ], + // 是否使用session + 'use_session' => true, 'session' => [ + 'id' => '', 'prefix' => 'think', 'type' => '', 'auto_start' => true, diff --git a/library/think/session.php b/library/think/session.php index 6f4b1fbf..b3f69cb6 100644 --- a/library/think/session.php +++ b/library/think/session.php @@ -39,7 +39,7 @@ class Session if (isset($config['prefix'])) { self::$prefix = $config['prefix']; } - if (isset($config['id'])) { + if (isset($config['id']) && !empty($config['id'])) { session_id($config['id']); } if (isset($config['name'])) {