'Handling PHP URL and GET requests
I am currently parsing any given url, for example example.com/page/1 or example.com/api/info/1, by exploding the URL:
$REQ = explode('/', $_SERVER['REQUEST_URI']);
array_shift($REQ);
$REQ = array_filter($REQ, function($value) { return $value !== ''; });]
and then accessing its elements in the array like so:
if (count($REQ) > 1 && $REQ[0] == 'page' && $REQ[1] == '1'){
\\ show page 1
}
But how could I handle (and access via array in the same way) a url that also includes GET elements, such as example.com/page?id=1 or example.com/api/info?=hello ?
I am using nginx and trying files like below:
location / {
index index.php;
try_files $uri /index.php?$query_string;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
