Table of Contents
Tutorial: How to Get Current Page URL in PHP with Source Code
About How to Get Current Page URL in PHP
Our Current url is https://www.campcodes.com/tutorials/php-tutorials/7631/how-to-get-current-page-url-in-php/
Source Code
$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
Source Code
$actual_link = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $actual_link ;

Output :
https://www.campcodes.com/tutorials/php-tutorials/7631/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.
Next Step for Your Project Journey
Pick your next action to keep building: download complete source code, continue with practical tutorials, or explore more project systems.

