hello i have a question how to use sessions.
i would like to change the language of a site. so the logic of the language settings is the following:
when calling my site it will be checked, if there is a browser_accept_language.
if there is a language setting it will be used as a preferred language otherwise the default language is set.
in the next step it will be checked if there is already a setting for it stored in a session.
if there is a session value for language the preferred language will be changed to the session entry.
okay, that is the logic part. now i tried to code. the problem is that it seems not working and i have no clue why.
so the php is:
<?PHP
session_start();
header ("Content-Type: text/html; charset=utf-8");
include_once "scripts/db_connect.php";
if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])){
$max = 0.0;
$languages = explode(",", (strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"])));
foreach($languages as $language){
$language = explode(';', $language);
$q = (isset($language[1])) ? ((float) $language[1]) : 1.0;
if ($q > $max){
$max = $q;
$pref_language = $language[0];
}
}
$pref_language = trim($pref_language);
}
$_SESSION['language'] = $pref_language_changed;
if (isset ($_SESSION['language']) ){
$pref_language = $pref_language_changed;
}...
followed by some html for mainwrapper the footer:
if ($pref_language === "af" OR $pref_language === "en"{
$footer = "footer1";
}else{
$footer = "footer2";
}
include_once "../scripts/".$footer.".php";
and the footer itself is:
... <ul class="flag">
<li id="'.$language_flag.'">
<ul class="drop_down">
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<a href="/foo"><li id="one"><div>language1</div></li></a>
<a href="/bar"><li id="two"><div>language2</div></li></a>
</form>
</ul>
</li>
</ul>...
<!--Footer -->';
if (isset($_POST['one'])){
$_SESSION['language'] = "language1";
}
if (isset($_POST['two'])){
$_SESSION['language'] = "language2";
}
?>
this is what all my pages are built of.
if there is someone who could tell me how to use sessions i really would appreciate.
thanks alot.
Try this
Also when you want to link an
<li>use
Dont use the a href outside the
<li>