I use this code to get the full URL:
$actual_link = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
The problem is that I use some masks in my .htaccess
, so what we see in the URL is not always the real path of the file.
What I need is to get the URL, what is written in the URL, nothing more and nothing less—the full URL.
I need to get how it appears in the Navigation Bar in the web browser, and not the real path of the file on the server.
Here is my solution - code is inspired by Tracy Debugger. It was changed for support different server ports. You can get full current URL including
$_SERVER['REQUEST_URI']
or just the basic server URL. Check my function:Here is test code:
For more: https://codeupweb.wordpress.com/2017/10/11/how-to-get-the-full-url-of-page-using-php/
This is quite easy to do with your Apache environment variables. This only works with Apache 2, which I assume you are using.
Simply use the following PHP code:
My favorite cross platform method for finding the current URL is:
Clear code, working in all webservers (Apache, nginx, IIS, ...):
Same technique as the accepted answer, but with HTTPS support, and more readable: