Wednesday, August 20, 2008

How to get current executing file in php

When you need to get the currently executing php script, you can use $_SERVER["SCRIPT_NAME"] to get the full path of the executing file, then you can easily explode the returned string and get the file name only.
Look at the code below


<?php

//get current executing page
//you get the full directory path
//ex: /test/path.php

$file_path = $_SERVER["SCRIPT_NAME"];

//so we expolde it into an array
$parts = Explode('/', $file_path);

//need to get the last element from array
$file_name = $parts[count($parts) - 1];

echo $file_name; //path.php

?>


Get Free Sinhala IT Learning Videos Kuppiya.com

 Subscribe To My Blog

No comments:

Post a Comment