Change language of site with a html button
you can do this by
<a href="index.php?language=en">
<a href="index.php?language=no">
and get the languages and store them in cookie and include file according to cookie like
if ( !empty($_GET['language']) ) {
$_COOKIE['language'] = $_GET['language'] === 'en' ? 'en' : 'nl';
} else {
$_COOKIE['language'] = 'nl';
}
setcookie('language', $_COOKIE['language']);
and than
if ( $_COOKIE['language'] == "en") {
include("headerEn.php");
} else {
include("header.php");
} ?>
To give a solution without changing your approach, You can do like this.
<?php
if(isset($_GET['language']))
$language = $_GET['language'];
else
$language = "";
if ($language == "en") {
include("headerEn.php");
} else {
include("header.php");
} ?>
<a href="index.php?language = en"><img src="images/language/languageNO.png"> </a>
<a href="index.php?language = no"><img src="images/language/languageEN.png"></a>
If you want to keep the selection, you can store this value in Database or Session.
It is always good to have a default value, so that you never end up being in a no-language site.
$language = $_REQUEST["language"];
$default_header="myheaderXXX.php";
switch ($language) {
case "en":
include("headerEn.php");
break;
case "no":
include("header.php");
break;
default:
include($default_header);
}
And then create links like this:
<a href="index.php?language=en">
<a href="index.php?language=no">