...

View Full Version : php url variables



weronpc
10-25-2003, 07:42 PM
Hello everyone,

right now the url is http://localhost?var1=99&var2=88
If I want to add var3=77 to http://localhost?var1=99&var2=88
What should or can I do?

when I use $_SERVER['PHP_SELF'] it only create link to http://localhost but without ?var1=99&var2=88
I want to add var3=77 to the end of the address, anyone know the best way to do this??

thank you so much

ConfusedOfLife
10-25-2003, 08:05 PM
I'm not quite sure what you want and where you wana use it, but you can always use a concatanation like:



print $_SERVER["PHP_SELF"] . "?var1=99?var2=88?var3=77";

maltrecho
10-25-2003, 08:26 PM
If I understood the question:

Get the vars first:

$var1 = $_GET['var1'];
$var2 = $_GET['var2'];
$var3 = '77';

You say $_SERVER['PHP_SELF'] is giving you only http://localhost, so there you are:

$url = "".$_SERVER['PHP_SELF']."?var1=".$var1."&var2=".$;var2."&var3=".$var3."";

Basically what ConfusedOfLife says. (we were writing at the same time)

Nightfire
10-25-2003, 08:34 PM
Won't $_SERVER['QUERY_STRING'] work?

weronpc
10-26-2003, 01:44 AM
the initial address is http://localhost?var1=99&var2=88

now, I want to add var3=77 to the end

maybe later, I will add var4=##

then var5=##

you know... keep on going.. is there a way to grab the host name + all the vars that's in the url???

thank you all for your quick reply..

Spookster
10-26-2003, 02:35 AM
Originally posted by weronpc
the initial address is http://localhost?var1=99&var2=88

now, I want to add var3=77 to the end

maybe later, I will add var4=##

then var5=##

you know... keep on going.. is there a way to grab the host name + all the vars that's in the url???

thank you all for your quick reply..

Well you can grab the URL using a server variable. You can grab the variables in the URL using the $_GET[] array. You don't have to know their names. You can just loop through the array like you would any other and generate a link using that and concatenate on the next variable and value.

missing-score
10-26-2003, 03:19 AM
$link = $_SERVER['PHP_SELF'].$_SERVER['QUERY_STRING'];



is that what you want?

Spookster
10-26-2003, 03:28 AM
As many times as I've looked through the server variables listed in the manual I had never seen query_string before now. Nice.

missing-score
10-26-2003, 04:08 AM
its on this page

http://www.php.net/manual/en/reserved.variables.php#reserved.variables.server


you have to be careful tho, becuase in a script i was writing, i kept getting errors when there was no query string. it seems that the $_SERVER['QUERY_STRING'] is not even set if there is no query string, rather than it just being an empty string.

Nightfire
10-26-2003, 12:31 PM
:( lol that's what I said a few posts back

Spookster
10-26-2003, 01:08 PM
Originally posted by Nightfire
:( lol that's what I said a few posts back

It's okay. I missed yours the first time because it was so small. Very nice. :thumbsup:

weronpc
10-26-2003, 02:34 PM
You guys are good, thank you...

Sorry Nightfire, I missed your reply...

you guys forgot "?"

$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']

missing-score
10-26-2003, 02:49 PM
yeh sorry nightfire, i missed that too

Nightfire
10-26-2003, 02:52 PM
lol no problem, atleast the problem's solved :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum