Say, you have 2 files currently, index-english.html
and index-german.html
You now create a file called index-global.php
. Whether the first two pages are fully HTML or contain PHP, doesn't matter, but you should keep the current extension.Thanks to fred-ii for mentioning that you should change the extension to .php for the HTML-pages
In the index-global.php
you'll place the following code
if (isset($_GET['lang']) AND $_GET['lang'] == "en") require("index-english.html");
elseif (isset($_GET['lang']) AND $_GET['lang'] == "de") require("index-german.html");
else {
header("Location: /?lang=en"); //redirect if no language specified
exit();
}
A better way would be to check the language automatically based on the Accept-Language
-header, for example
$languages_supported_by_client = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($language_supported_by_client as $language) {
if($language == "en") {
require("index-english.html");
exit();
}
elseif($language == "de") {
require("index-german.html");
exit();
}
}
require("index-english.html");
exit();
In this case the asker wanted to include all HTML in one file
$languages_supported_by_client = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
foreach ($language_supported_by_client as $language) {
if($language == "en") {
?>English HTML content here<?php
exit();
}
elseif($language == "de") {
?>German HTML content here<?php
exit();
}
}
?>English HTML content here<?php
exit();