468,247 Members | 1,338 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,247 developers. It's quick & easy.

Variables being APPENDING in URL and Address bar. Why ?

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!

Mar 7 '06 #1
4 1971
da**********@gmail.com wrote:
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!


Don't echo the query string.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 7 '06 #2
Syl
ARGH!!!! Of course!

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

Mar 7 '06 #3
da**********@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.

Mar 8 '06 #4
Syl wrote:
ARGH!!!! Of course!

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


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.
js*******@attglobal.net
==================
Mar 8 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by plittle1970 | last post: by
5 posts views Thread by Pseud O'Nym | last post: by
5 posts views Thread by Christopher M. Lusardi | last post: by
2 posts views Thread by Newbie | last post: by
3 posts views Thread by hharry | last post: by
3 posts views Thread by Jim | last post: by
25 posts views Thread by sidd | last post: by
reply views Thread by zattat | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.