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.
Solution
<?php
$currentUrl=””;
$currentUrl=$_SERVER[“HTTP_HOST”]; // it gives the root url
$currentUrl.=$_SERVER[“REQUEST_URI”]; // it gives the rest url and we concatenated with $current url
$currentUrl=’https://’.$currentUrl;
echo $currentUrl;
?>
Output: https://localhost/gyanol/test.php