Is there a simple way to get the requested file or directory without the GET arguments? For example, if the URL is http://example.com/directory/file.php?paramater=value
I would like to return just http://example.com/directory/file.php
. I was surprised that there is not a simple index in $_SERVER[]
. Did I miss one?
相关问题
- Views base64 encoded blob in HTML with PHP
- Angular RxJS mergeMap types
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
Not everyone will find it simple, but I believe this to be the best way to go around it:
What is does is simply to go through the REQUEST_URI from the beginning of the string, then stop when it hits a "?" (which really, only should happen when you get to parameters).
Then you create the url and save it to $url:
When creating the $url... What we're doing is simply writing "http" then checking if https is being used, if it is, we also write "s", then we concatenate "://", concatenate the HTTP_HOST (the server, fx: "stackoverflow.com"), and concatenate the $return, which we found before, to that (it's an array, but we only want the first index in it... There can only ever be one index, since we're checking from the beginning of the string in the regex.).
I hope someone can use this...
PS. This has been confirmed to work while using SLIM to reroute the URL.
I actually think that's not the good way to parse it. It's not clean or it's a bit out of subject ...
I'd do something like ...
Considering $app_uri as the URI/URL of my website.
I had the same problem when I wanted a link back to homepage. I tried this and it worked:
Note the question mark at the end. I believe that tells the machine stop thinking on behalf of the coder :)
Why so complicated? =)
this should really do it man ;)
Solution:
echo
parse_url
($_SERVER["REQUEST_URI"], PHP_URL_PATH);
I know this is an old post but I am having the same problem and I solved it this way
Or equivalently