-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
31 lines (28 loc) · 923 Bytes
/
index.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
<?php
// Define supported languages and corresponding directories
$supported_languages = array(
'es' => '/index.html',
'en' => '/en/index.html',
);
// Get the user's preferred language from the Accept-Language header
function get_user_language() {
$languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($languages as $language) {
$language = explode(';', $language);
if (strlen($language[0]) == 2) {
return $language[0];
}
}
return 'en';
}
// Redirect the user to the appropriate directory based on their preferred language
function redirect_to_language_directory() {
$user_language = get_user_language();
if (array_key_exists($user_language, $supported_languages)) {
header('Location: ' . $supported_languages[$user_language]);
exit;
}
}
// Call the function to redirect the user
redirect_to_language_directory();
?>