In the footer of each page I have a footer with flags to change language thanks to the GET:
<a href="<?= $url.$var ?>lang=en_US"><img class="flag" src="images/us_flag.png" /><span>English</span></a> |
<a href="<?= $url.$var ?>lang=fr_FR"><img class="flag" src="images/fr_flag.png" /><span>Français</span></a> |
<a href="<?= $url.$var ?>lang=de_DE"><img class="flag" src="images/de_flag.png" /><span>Deutsch</span></a> |
<a href="<?= $url.$var ?>lang=zh_CN"><img class="flag" src="images/ch_flag.png" /><span>中文</span></a>
I want to make these dynamic links to adapt to all pages of the site, so I did this:
<?php
$url = $_SERVER['REQUEST_URI'];
$var = ($_GET) ? '&': '?';
?>
The problem is when I click on the links to change languages, it adds a language parameter like this:
mysite.com/folder/?status=super&number=90&lang=fr_FR&lang=en_US&lang=en_US&lang=en_US
So how can I do that if the lang parameter is already present in $_SERVER['REQUEST_URI']
, just replace it in the link
If possible a simple and effective solution (when it will be called at each page loading)