How To Get Current Page URL In PHP | Free Source Code

How to Get Current Page URL in PHP

PHP
how to get current page url in php

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 ;
how to get current page url in php

how to get current page url in php

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.

Facebook Comments

Leave a Reply

Your email address will not be published.