Reply to Re: Variables being APPENDING in URL and Address bar. Why ?

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация