I'm pretty sure this was working before, so I don't know what happened to the code I had in place for a language selector I've been using for a site in development. Here is the php:
<?php
session_start();
if(isset($_POST['language'])) {
$_SESSION['language'] = $_POST['language'];
}
$language = (isset($_SESSION['language']) ? $_SESSION['language'] : "english");
include('/Languages/'.$language.'.php');
?>
The HTML:
<form method="post">
<input type="image" name="language" value="english" src="Images/english.png"/>
<input type="image" name="language" value="spanish" src="Images/spanish.png"/>
...
</form>
The PHP in each 'dictionary' file:
<?php
$content = array(
"identifier1"=>'content with html to be included',
"identifier2"=>'more content to be included'
);
?>
And finally, the code on the actual page to call the right language:
<?php echo $content['identifier1']; ?>
So this is supposed to work by having the user click one of the images in the form. The form sends the value of the clicked image, which is the name of the language file that should be opened. The PHP, which is in the head of the page, then takes this value, and includes the dictionary file (eg, english.php), which can then be referred to in the HTML from the echo above.
However, I cannot get this to work. When I click on the image, the page reloads. I've tried doing a <?php echo 'stuff'; ?>, and that works, so my PHP should be working. This means that something must be wrong with the code.
<form method="post">with no action. By default, having no action is like posting to self.<?php echo $content['index1']; ?>be<?php echo $content['identifier1']; ?>? And your form elements, if they are inputs, may need different names. Both are set toname="language"