Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • Last Modified:

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
0
Bohne
Asked:
Bohne
  • 3
1 Solution
 
Richard QuadlingSenior Software DeverloperCommented:
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
 
Richard QuadlingSenior Software DeverloperCommented:
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 DeverloperCommented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now