Reputation: 897
How can I retrieve the query_string, or the parameters after the '?' in the URL if it was hardcoded, and not sent through from a form?
I would normally use $_GET['name'] to retrieve this data, but since I am looking for a method to retrieve the query when someone has hardcoded by directly typing the query_string into the URL, I am unsure what the 'name' would be to use $_GET.
Is this possible?
Upvotes: 0
Views: 104
Reputation: 14419
<?php
foreach($_GET as $key => $value)
echo $key . " : " . $value;
?>
Upvotes: 0
Reputation: 59699
It seems that your problem is you don't know what key the user is going to type in for the $_GET
parameter. So, you can directly loop through $_GET
like this:
foreach( $_GET as $key => $value) {
echo $key . ' => ' . $value . "\n";
}
This will print all of the parameters.
Now, if you only want the first GET parameter, you can use array_shift()
, like this:
$first = array_shift( $_GET);
Both methods do not require you to know the key of the parameter beforehand.
Upvotes: 1