How to get the current URL?
To get the current url ( relative to the document root), you may use this script:
$URL = $_SERVER['PHP_SELF'];
echo $URL;
?>
But if your page is www.domain.com/folder1/page.php?a=25&b=12 , it will display only: "/folder1/page.php" , $_SERVER['PHP_SELF'] don't include the query string .
If you want to include the query string, use this script:
$URL = $_SERVER['REQUEST_URI'];
echo $URL;
?>
How to get the file path?
To get the path of the executing file in the server, you may use:
$path = $_SERVER['SCRIPT_FILENAME'];
echo $path;
?>
or
/var/www/htdocs/test/page.php
To get the current file name, we will use the same code to get the url:
$url = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $url);
$file = $break[count($break) - 1];
echo $file;
?>