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?
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.
<?php
foreach($_GET as $key => $value)
echo $key . " : " . $value;
?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.