I'm building a small static website in HTML and PHP. The website include two languages, Spanish and English. Spanish is the language set by default.
I think I have an issue with the PHP code. When I click the links to switch languages it doesn't work. You can easily reproduce the issue with the following code divided in 4 different PHP files.
index.php
<!doctype html>
<html class="no-js" lang="es">
<head>
<meta charset="utf-8">
</head>
<body>
<?php
if (empty($_SESSION["langfile"])) { $_SESSION["langfile"] = "spanish.php"; }
require_once ($_SESSION["langfile"]);
echo $language["hi"];
?>
<a href="language.php?l=english">En</a>
<a href="language.php?l=spanish">Es</a>
</body>
</html>
language.php
<?php
if (!empty($_GET["l"]))
{
$_SESSION["langfile"] = $_GET["l"] . ".php";
header ("location: index.php"); exit();
}
?>
spanish.php
<?php $language["hi"] = 'Hola'; ?>
english.php
<?php $language["hi"] = 'Hello'; ?>
Any help would be much appreciated, thank you!