From 18421fc152d86685222c1fd3a9f3291546f360eb Mon Sep 17 00:00:00 2001 From: Ling Date: Thu, 29 Sep 2016 15:40:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=B9=E6=B3=95-=E5=A4=9A?= =?UTF-8?q?=E8=AF=AD=E8=A8=80-=E8=AE=BE=E7=BD=AE=E5=A4=9A=E8=AF=AD?= =?UTF-8?q?=E8=A8=80cookie=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Lang.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/library/think/Lang.php b/library/think/Lang.php index 1e7bf197..16e7f545 100644 --- a/library/think/Lang.php +++ b/library/think/Lang.php @@ -25,6 +25,8 @@ class Lang protected static $langDetectVar = 'lang'; // 语言Cookie变量 protected static $langCookieVar = 'think_var'; + // 语言Cookie的过期时间 + protected static $langCookieExpire = 3600; // 允许语言列表 protected static $allowLangList = []; @@ -155,7 +157,7 @@ class Lang if (isset($_GET[self::$langDetectVar])) { // url中设置了语言变量 $langSet = strtolower($_GET[self::$langDetectVar]); - Cookie::set(self::$langCookieVar, $langSet, 3600); + Cookie::set(self::$langCookieVar, $langSet, self::$langCookieExpire); } elseif (Cookie::get(self::$langCookieVar)) { // 获取上次用户的选择 $langSet = strtolower(Cookie::get(self::$langCookieVar)); @@ -163,7 +165,7 @@ class Lang // 自动侦测浏览器语言 preg_match('/^([a-z\d\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches); $langSet = strtolower($matches[1]); - Cookie::set(self::$langCookieVar, $langSet, 3600); + Cookie::set(self::$langCookieVar, $langSet, self::$langCookieExpire); } if (empty(self::$allowLangList) || in_array($langSet, self::$allowLangList)) { // 合法的语言 @@ -195,6 +197,16 @@ class Lang self::$langCookieVar = $var; } + /** + * 设置语言的cookie的过期时间 + * @param string $expire 过期时间 + * @return void + */ + public static function setLangCookieExpire($expire) + { + self::$langCookieExpire = $expire; + } + /** * 设置允许的语言列表 * @param array $list 语言列表