2.1 版本文件
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 语言切换页(服务端)。
|
||||
* 用法:<a href="lang.php?lang=en_US">English</a>
|
||||
* 本页设置 $_SESSION['lang'] + cookie 后,重定向回来源页(或首页)。
|
||||
*/
|
||||
require __DIR__ . '/includes/init.php';
|
||||
|
||||
$lang = trim($_GET['lang'] ?? '');
|
||||
$allowed = [];
|
||||
foreach (Lang::available() as $l) {
|
||||
$allowed[] = $l['code'];
|
||||
}
|
||||
|
||||
if ($lang !== '' && in_array($lang, $allowed, true)) {
|
||||
$_SESSION['lang'] = $lang;
|
||||
setcookie('fnw_lang', $lang, time() + 31536000, '/');
|
||||
Lang::setLocale($lang);
|
||||
}
|
||||
|
||||
// 重定向回来源页,避免跳转到站外
|
||||
$ref = $_SERVER['HTTP_REFERER'] ?? '';
|
||||
$host = parse_url((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https://' : 'http://') . ($_SERVER['HTTP_HOST'] ?? ''), PHP_URL_HOST);
|
||||
if ($ref === '' || parse_url($ref, PHP_URL_HOST) !== $host) {
|
||||
$ref = '/';
|
||||
}
|
||||
header('Location: ' . $ref, true, 302);
|
||||
exit;
|
||||
Reference in New Issue
Block a user