Check if Acccept-Language header is empty before using it

This commit is contained in:
Thijs Raymakers 2025-02-27 00:07:54 +01:00
parent 0094d7cbbd
commit 607234d727
No known key found for this signature in database
4 changed files with 9 additions and 4 deletions

View file

@ -1,8 +1,7 @@
<?php
require_once("language/language.php");
header("Access-Control-Allow-Origin: *");
$lang = Language::getPreferredLanguage();
echo $lang->get("Test");
?>

View file

@ -8,4 +8,5 @@ class English extends Language {
}
}
return new English();
?>

View file

@ -14,7 +14,11 @@ class Language {
}
public static function getPreferredLanguage() {
$language = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
if (empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$language = "en";
} else {
$language = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
}
$languages = array(
"en",

View file

@ -8,4 +8,5 @@ class Dutch extends Language {
}
}
return new Dutch();
?>