Posted by Codik on 03/08/06 16:16
david.hunter@gmail.com napísal(a):
> I have a hyperlink in the footer so that the user can toggle between
> languages. The toggle works, but the language parameter is being
> APPENDED into the URL and in the address bar of the browser - like this
> :
> &lang=fr&lang=en&lang=fr&lang=en&lang=fr
>
> Why is this happening and how can I stop it ?
>
> Here is my footer.php code :
> <a href="http://website.com/<?php echo
> $_SERVER['SCRIPT_NAME'] ?>?<?php echo $_SERVER['QUERY_STRING']
> ?>&lang=<?php echo $toggle ?>"><?php echo MENU_TOGGLE ?></a>
Good day.
It is happening because variable $_SERVER['QUERY_STRING'] contains
&lang and You want add next in Your script. You must filter it. You can
use this (footer.php):
<?php
$new_qs = preg_replace("/(.*&?lang=)(?:.*?(&.*)|(?:.*))/",
"\\1".$toggle."\\2", $_SERVER['QUERY_STRING']);
echo '<a
href="http://website.com/'.$_SERVER['SCRIPT_NAME'].'?'.$new_qs.'">'.MENU_TOGGLE.'</a>';
?>
--
When my English is bad, sorry.
[Back to original message]
|