Connecting Tech Pros Worldwide Help | Site Map

Variables being APPENDING in URL and Address bar. Why ?

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 7th, 2006, 06:45 PM
david.hunter@gmail.com
Guest
 
Posts: n/a
Default 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!


  #2  
Old March 7th, 2006, 07:05 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default 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, 07:45 PM
Syl
Guest
 
Posts: n/a
Default 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, 01:25 PM
Codik
Guest
 
Posts: n/a
Default 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, 05:55 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default 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
==================
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.