Reload page after click on to get new datta from PHP
I'm writing a multilingual web and the logic is next:
Buy default there is a "lang.tmp" file with default data "eng".
When index.php loads it takes data from "lang.tmp" and sets the default
language loading data from lang.php:
include("lang/".file_get_contents("lang.tmp").".php");
If user wants to change language, he clicks on link created with php,
which rewrites data in "lang.tmp":
include("lang/languages.php");
$i=0;
while (list($key, $value) = each($languages))
{
echo '<li class="lang"><a href="index.php?'.$key.'"><div
id="langBox">'.$value.'</div></a></li>';
if ($_SERVER['QUERY_STRING'] == $key)
{
$fp=fopen("lang.tmp","w");
fwrite($fp,basename($key));
fclose($fp);
}
SO! The problem is: after rewriting the "lang.tmp" file I need to reload
the page with the same "index.php" adress to get new type of language.
I've tried
header("Location: index.php");
and obviously it doesn't work because URL is the same, so I'm getting error:
Warning: Cannot modify header information - headers already sent.
I also tried JavaScript:
$("div #langMenu").click(function() {
location.reload();
console.log ("Clicked!");
});
But it doesn't worked either. Page reloads with new language only after
second click on a link, but that's not what everybody needs ))
Would you be so kind to link where I'm wrong or what are the other options
to reload page in this situation.
Thank you in advance.
No comments:
Post a Comment