Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload