473,396 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 2162
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: plittle1970 | last post by:
Hi there. My website passes information from one page to another via the URL. it DOESN'T use forms or post/get but rather I build up the url in page A as a string and use it to link to page B. ...
1
by: dmiller23462 | last post by:
Hey guys.... I put an error-handling in my page and have it posted at the complete end of the code, see below(when people were putting in 's I was getting the delimiter errors). Great, I...
5
by: Pseud O'Nym | last post by:
Hi all, and apologies if this is a newbie type question, I am one. I need to get a page to go to a paticular <a name=""> tag. It works fine with no variables passed eg: myscript.php#top, but I...
7
by: PC Datasheet | last post by:
Looking for suggestions ---- A database was designed for a national automobile inspection program. In it's simplest form, the database has two tables: TblOwner OwnerID <Year/Make/Model owned...
5
by: Christopher M. Lusardi | last post by:
Hi, I know about the convention of appending "_" to c routine names, but how do I access Fortran global variables in c? Thank you, Christopher Lusardi
2
by: Newbie | last post by:
Hi All, I would really appreciate any ideas / clues on this issue which I am facing. I have a asp.net application, the problem is with maintaining session variables while using authentication for...
3
by: hharry | last post by:
Hi All, If I have the following xml: <Response> <AddressDetails> <Address> </Address> </AddressDetails> </Response>
3
by: Jim | last post by:
Could anyone please point me towards some code that allows me to add to an existing XML file using the output of an HTML form. I want to add a form on my website so users can input their email...
25
by: sidd | last post by:
In the following code: int i = 5; ---it goes to .data segment int j; ---it goes to bss segment int main() { int c; int i = 5; ---stack
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.