Forum Moderators: coopster

Message Too Old, No Replies

need help with link generation & get variables

         

sebbothebutcher

3:06 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



hi!
i have a page, and wenn somebody clicks an element in the page's menu
?submenu=whateverwascliked
is attached to the current adress.
now what i want is to generate a link that should (if there are no get variables attached) load
index.php?lang=en
and if there is already a variable (for example some?submenu) it should write:
index.php?submenu=whateverwasclicked&lang=en
since
$_SERVER['PHP_SELF']
doesn't respect the get variables, i can't use that...
any suggestions for this problem?
thanks in advance

sebbothebutcher

9:11 pm on Jun 17, 2004 (gmt 0)

10+ Year Member



okay i've found a way round it now, but it would be still nice to have a solution since it may be useful for other people or even for me in my further life which i hope to last very long since i'm 15 now... ;-)

jatar_k

10:42 pm on Jun 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>>i have a page, and wenn somebody clicks an element in the page's menu

so do you hard code the get var into the <a> or do you do something else.

If you are looking for a default setting you could do

if (!isset($_GET['lang'])) $language = 'en';

then links can be

<a href="index.php?submenu=whateverwasclicked&lang=<? echo $language;?>">

is that what you mean?

sebbothebutcher

12:59 pm on Jun 18, 2004 (gmt 0)

10+ Year Member



what i meant was the following:
if the visitor is on a page with the adress
http://mydomain.com/dir/index.php

and he clicks a specific link, "?lang=en" is added, but if there is already something attached, for example the adress is
http://mydomain.com/dir/index.php?id=1
then
&lang=en
should be added...
this script should work with every adress... any suggestions?
i've found another way now to solve this language change problem, but it still would be great for the future!

CompressedAir

4:11 pm on Jun 18, 2004 (gmt 0)

10+ Year Member



Hmm..
so something like:

if ($_SERVER['REQUEST_URI']=="/dir/index.php") {
$lang="en";
}

or

if (!isset($_GET['lang']) ) {
$lang="en";
}

then in your links:

printf("<a href=\"/dir/index.php?id=%slang=%s\">Link</a>", $id, $lang);

Something like that should work :)

WhosAWhata

7:37 pm on Jun 21, 2004 (gmt 0)

10+ Year Member



if you want to find all of the vars passed by get

if(count($_GET)) {
foreach ($_GET as $k => $v){
$add .= "&".$k."=".$v;
}
}
//then on your links
echo "<a href=\"index.php?lang=en".$add."\">";

sebbothebutcher

7:53 pm on Jun 21, 2004 (gmt 0)

10+ Year Member



okay... thanks to all of you for your help!