How to access current file location and show on screen in php using $_SERVER[‘PHP_SELF’] .
In this tutorial we are simply getting current file url ( Universe resource locator ) including sub folder name. So here is the complete step by step tutorial for How to get current file url in PHP.
How to get current file url in PHP.
Code for current-file-url.php file.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Get current file path in PHP</title> </head> <body> <?php $URL = $_SERVER['PHP_SELF']; echo $URL; ?> </body> </html>
Screenshot:
Brief description : My blog’s name is Android-Examples.com so if my file path is Android-Examples.com/upload/file.php then it will display only /upload/file.php . But if you are using &mod=, ?id=121 or Android-Examples.com/demopage12.php?id=121 then it will only display /demopage12.php so to show the whole url you have to use $_SERVER[‘REQUEST_URI’] it will return the whole page url including the ? and = symbols.
Code for get-whole-url.php file.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php $URL = $_SERVER['REQUEST_URI']; echo $URL; ?> </body> </html>
Screenshot: