Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple URL help

Status
Not open for further replies.

jamesp0tter

Programmer
Feb 20, 2003
119
PT
i found sometime ago the way to use
blabla.php?var
instead of blabla.php?somevar=var

but i've lost it :X

can someone please remind me ? ;)

tks !


jamesp0tter,
jamespotter@netcabo.pt

p.s.: sorry for my (sometimes) bad english :p
 
hum.. :#

if i do a count($_GET) when i use .php?a i get 0 but then i use .php?a=b i get 1

so i can't go there and grab the key because it's not even in the array right ? :


jamesp0tter,
jamespotter@netcabo.pt

p.s.: sorry for my (sometimes) bad english :p
 
That's odd.

Using the following test script, test_show_get.php:

Code:
<?php
print '<pre>';
print 'Count:' . count($_GET). &quot;\n&quot;;
print_r ($_GET);
?>

When I point my browser to test_show_get.php, I get:

Code:
Count:0
Array
(
)

But when I point my browser to test_show_get.php?a, I get:

Code:
Count:1
Array
(
    [a] => 
)

This is on a LAMP (RH9/1.3.28/4.0.14/4.3.4) box. What version of PHP are you running?


Want the best answers? Ask the best questions: TANSTAAFL!!
 
strange..

i get
Count:0
Array
(
)
if i put .php?a

and

Count:1
Array
(
[a] => 1
)

if i put .php?a=1

:(
php version 4.2.2
is it the version ? :
jamesp0tter,
jamespotter@netcabo.pt

p.s.: sorry for my (sometimes) bad english :p
 
It's probably a revision problem.

It sounds like a change in the way PHP parses the URL. To be honest, you shouldn't trust the solution I gave you unless you know for a fact that you are seeing a but that has been fixed. For all we know, the output I'm getting is wrong and yours right.


Here's a better answer. Look in $_SERVER['QUERY_STRING'] instead.

In the case of script.php?a, that variable will contain &quot;a&quot;.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
.php?a&foo=3

Count:1
Array
(
[a] =>
)

wow that's odd :x lol

that $_SERVER['QUERY_STRING'] was just the thing i was looking for :) i used to use it but then forgot it..

thanks ;)
[[]]

jamesp0tter,
jamespotter@netcabo.pt

p.s.: sorry for my (sometimes) bad english :p
 
ehe i can't upgrade because it is running on a remote pc, in my shell provider :p i think i'll suggest upgrade :)

tk u again

jamesp0tter,
jamespotter@netcabo.pt

p.s.: sorry for my (sometimes) bad english :p
 
If you're just looking to pass a single variable with the URL, you can use $_SERVER['QUERY_STRING'] to get it. It should just pass anything after the ? in the URL.

Using the following as testparse.php
<? PHP
$urlvar = $_SERVER['QUERY_STRING'];
print &quot;$urlvar was typed after the URL&quot;;
?>

If called with testparse.php?foo the resulted output is

foo was typed after the URL

 
Ok, so I'm sleepy. I either missed that chunk or I had the page open so long before I finally got around to finishing the thread. Had a small fire to put out at work.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top