PHP Basics

What is the PHP function for obtaining current URL of the web page?

In some cases, we may need to get the current url of the webpage. PHP has super global variables which holds the data related to the webpage url.

$_SERVER super global variable

PHP has this variable $_SERVER it contains all the web url related info.

We need to get two data, one is request uri, second one is http host.




$currentUrl=$_SERVER[“HTTP_HOST”]; // it gives the root url

$currentUrl.=$_SERVER[“REQUEST_URI”]; // it gives the rest url and we concatenated with                                                                                                                       $current url


echo $currentUrl;


Output: https://localhost/gyanol/test.php