Detecting the Absolute URI
In PHP there's a function called parse_url which splits a given absolute url into various parts as an array.
You can probably get the absolute URI with something as simple as : but unfortunately, how filename & directory name values are stored in $_SERVER varies in server setup and relying on it may not be 100% accurate, though in 99% of the cases, it should do just fine.There's another reason to use the 2nd snippet instead of the 1st - that's if a RewriteRule is used for the given current url ($ThisLink).
Lets say I had the 1st code snippet in absURI.php in test folder in my document root. So http://localhost/test/absURI.php would be the link. And something like this in my .htaccess file : and I access the url using http://localhost/test/fakefolder/test.html?a=2&b=c
AbsURI() will end up returning http://localhost/test/fakefolder/ which would be incorrect.
Tested on different hosts having Apache 2.0.x.
| Filed Under : php | |||||||||
| Posted by Anjanesh on Monday, August 13, 2007 | |||||||||
0 comments:
Post a Comment