window.location.search in php?!?

Hi,

how can I get the variable after the ? in the address line? (phptest.php?variable) In javascript it's window.location.search. But how is it called in php? Or is this not possible in php, because php is server based???

thanks
BohneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Richard QuadlingSenior Software DeveloperCommented:
Try ...

$_SERVER['QUERY_STRING'];

For a complete list of available variables, try ...

<?php phpinfo(); ?>

Richard.
0
jayrodCommented:
Then you can use the parse() function to get all of the variables in the format of:

?variable=something?variable2=otherthing
0
alakritiCommented:
when there are things in the Query String like this

page.php?var=value&var2=something

all u need to do to grab the contents of them would be to use $_GET['var'] and $_GET['var2'] if you are using an older version of PHP it would be $HTTP_GET_VARS['var'] and $HTTP_GET_VARS['var2']

hope this helps. :)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard QuadlingSenior Software DeveloperCommented:
Alakriti.

That is absolutely right for name/value pairs.

But it doesn't work for ...

www.site.com/page.php?var1&var2&var3

Richard.
0
Richard QuadlingSenior Software DeveloperCommented:
Oops. I'm wrong.

The variables ARE processed into $_GET / $HTTP_GET_VARS, but without values!

So,

print_r($_GET);

returns

Array
 (
 "var1" =>
 "var2" =>
 )

You would be able to use ...

foreach($_GET as $key => $value)
 {
 echo "The variable '$key' was supplied with the value '$value'.\n";
 }

to get to each variable sent.

Richard.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.