Connecting Tech Pros Worldwide Help | Site Map

Variables being APPENDING in URL and Address bar. Why ?

  #1  
Old March 7th, 2006, 07:45 PM
david.hunter@gmail.com
Guest
 
Posts: n/a
Hi - my site is bilingual.
I have two language files that look like this :
en.inc
define(HELLO, 'Hello');
fr.inc
define(HELLO, 'Bonjour');

Then my php/html looks like this:
<h3><?php echo HELLO ?></h3>

In each page I check and/or set the language :
index.php :
$lang='en';
require('languages/set_language.php');

set_language.php :
if (isset($_GET['lang'])) {
$lang = $_GET['lang']; }
require("{$lang}.inc");

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>

THANK YOU!

I know it's not practical for people to be going back and forth between
languages - but this problem is still annoying the heck out of me!

  #2  
Old March 7th, 2006, 08:05 PM
Jerry Stuckle
Guest
 
Posts: n/a

re: Variables being APPENDING in URL and Address bar. Why ?


david.hunter@gmail.com wrote:[color=blue]
> Hi - my site is bilingual.
> I have two language files that look like this :
> en.inc
> define(HELLO, 'Hello');
> fr.inc
> define(HELLO, 'Bonjour');
>
> Then my php/html looks like this:
> <h3><?php echo HELLO ?></h3>
>
> In each page I check and/or set the language :
> index.php :
> $lang='en';
> require('languages/set_language.php');
>
> set_language.php :
> if (isset($_GET['lang'])) {
> $lang = $_GET['lang']; }
> require("{$lang}.inc");
>
> 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>
>
> THANK YOU!
>
> I know it's not practical for people to be going back and forth between
> languages - but this problem is still annoying the heck out of me!
>[/color]

Don't echo the query string.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  #3  
Old March 7th, 2006, 08:45 PM
Syl
Guest
 
Posts: n/a

re: Variables being APPENDING in URL and Address bar. Why ?


ARGH!!!! Of course!

Thanks you so much Jerry - I should have posted my quesiton *hours*
ago!!!

  #4  
Old March 8th, 2006, 02:25 PM
Codik
Guest
 
Posts: n/a

re: Variables being APPENDING in URL and Address bar. Why ?


david.hunter@gmail.com napísal(a):[color=blue]
> 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>[/color]

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.

  #5  
Old March 8th, 2006, 06:55 PM
Jerry Stuckle
Guest
 
Posts: n/a

re: Variables being APPENDING in URL and Address bar. Why ?


Syl wrote:[color=blue]
> ARGH!!!! Of course!
>
> Thanks you so much Jerry - I should have posted my quesiton *hours*
> ago!!!
>[/color]

Sometimes you stare at the problem so long you can't see it. Then
someone else comes along and points out the obvious.

Don't know how many times it's happened to me! :-)

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
python-dev Summary for 2005-12-01 through 2005-12-15 Tony Meyer answers 0 January 20th, 2006 04:55 AM
FAQ update (roundup of pending requests - for comment) Richard Cornford answers 42 July 20th, 2005 02:38 PM