// // This is the default language; // This value is used if there's no languages set in the browser at all, // or none of the browser languages are matching the website languages; $Language = "nl"; // // List of languages available on the website; $WebSiteLanguages = array('nl','fr'); // // Implementation of the language checker if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $browserlangs = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); foreach ($browserlangs as $val) { if (preg_match('/^([a-z]{2,3})/i', $val, $matches)) { if (in_array($matches[1], $WebSiteLanguages)) { $Language = $matches[1]; break; } } } } // // SSL and port aware redirection if (isset($_SERVER['SERVER_PROTOCOL']) && preg_match('/((HTTPS)|(SSL))/i', $_SERVER['SERVER_PROTOCOL'])) { $Protocol = 'https'; if(isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '443')) { $Port = ":{$_SERVER['SERVER_PORT']}"; } else { $Port = ''; } } else { $Protocol = 'http'; if(isset($_SERVER['SERVER_PORT']) && ($_SERVER['SERVER_PORT'] != '80')) { $Port = ":{$_SERVER['SERVER_PORT']}"; } else { $Port = ''; } } // // Modifying the HTTP repsonse header to redirect the browser to the new URI header('HTTP/1.1 303 See Other'); header("Location: {$Protocol}://{$_SERVER['HTTP_HOST']}{$Port}/{$Language}/"); ?>