PHP program to print the filename of the current executing PHP script

Here, we are going to learn how to print the filename of the current executing PHP script in PHP?
Submitted by Nidhi, on November 24, 2020 [Last updated : March 14, 2023]

Getting Filename of the Current Executing PHP Script

Here, we will use $_SERVER['PHP_SELF'] superglobal to get the name of the currently executing file and print that on the webpage.

PHP code to get the filename of the current executing PHP script

The source code to print the filename of the current executing PHP script is given below. The given program is compiled and executed successfully.

<?php
//PHP program to print the filename of 
//current executing PHP script.

$fileName = $_SERVER['PHP_SELF'];

printf("File Name: %s<br>", $fileName);
?>

Output

File Name: prog.php

Explanation

In the above program, we used $_SERVER['PHP_SELF'] super global that returns the name of the currently executing file, which is assigned to the variable $fileName. After that, we printed the file name using printf() on the webpage.

More PHP Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.