I may be completely off base, but I'm pretty sure I've seen URLs structured like this before:
http://www.example.com/dir/?=1
with no visible parameter being passed, but a value given.
If this is a valid url structure, how would one get the parameter value 1
in PHP?
This value won't be available through $_GET
. I found it only in $_SERVER["QUERY_STRING"]
or $_SERVER["REQUEST_URI"]
. So I assume you have to parse these variables on your own.
Here's a quick and dirty function I use to read such URLs
function get_url_params() {
$param_count = 0;
$params = array();
foreach (explode('&', $_SERVER['QUERY_STRING']) as $param) {
$param = explode('=', $param);
if ($param[0] == '') {
$params[$param_count] = $param[1];
} else {
$params[$param[0]] = $param[1];
}
$param_count++;
}
return $params;
}
print_r(get_url_params());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With