-
Notifications
You must be signed in to change notification settings - Fork 3
/
apply-language.php
52 lines (45 loc) · 1.32 KB
/
apply-language.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
This file handles changes of user language.
*/
require_once("./includes/lib/global.php");
__require("i18n");
__require("security");
$returnpath = "./";
/*
As this script is for URL navigation only, only GET is supported. If a user
tries to POST this page, they should be redirected back to the main page.
*/
if ($_SERVER["REQUEST_METHOD"] !== "GET") {
header("HTTP/1.1 303 See Other");
header("Location: {$returnpath}");
exit;
}
/*
Perform CSRF validation.
*/
if (!Security::validateCSRF()) {
header("HTTP/1.1 303 See Other");
header("Location: {$returnpath}");
exit;
}
/*
Check if the selected language is available in FreeField. A blank string
means auto-detection should be used. FreeField will auto-detect when the
language cookie is missing, so we unset the language cookie in that case.
*/
$selected = !isset($_GET["lang"]) ? "" : $_GET["lang"];
$langs = I18N::getAvailableLanguages();
if (!in_array($selected, $langs)) $selected = "";
/*
Set/unset the language cookie and redirect.
*/
header("HTTP/1.1 303 See Other");
if ($selected == "") {
setcookie("language", "", time() - 3600, "/");
} else {
// Keep the cookie alive for as long as possible.
setcookie("language", $selected, time() + (86400 * 365 * 10), "/");
}
header("Location: {$returnpath}");
?>