Link to home
Start Free TrialLog in
Avatar of Bohne
Bohne

asked on

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
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Try ...

$_SERVER['QUERY_STRING'];

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

<?php phpinfo(); ?>

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

?variable=something?variable2=otherthing
ASKER CERTIFIED SOLUTION
Avatar of alakriti
alakriti
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Alakriti.

That is absolutely right for name/value pairs.

But it doesn't work for ...

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

Richard.
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.