How to get current page URL in php
Our Current url is https://phpgurukul.com/how-to-get-current-page-url-in-php/
1 2 |
$url=$_SERVER['REQUEST_URI']; echo $url; |
Output :
/how-to-get-current-page-url-in-php/
REQUEST_URI return only root website folder instead of returning full page.
if you want actual link then use this syntax
1 2 |
$actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; echo $actual_link ; |
Output :
https://phpgurukul.com/how-to-get-current-page-url-in-php/
In the above code $_SERVER[‘HTTP_HOST’] return the domain name through which the current request is being fulfilled.