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 语言列表