Need Name and Directory of Current Script

I have a script called “/account/profile.php” and need to capture the script name and parent directory.

This should be easy.

The problem is that I accomplish this by calling a function called “getPageInfo( )” located in another script which looks like this…

        echo "<p>basename(FILE): " . basename(__FILE__) . "</p>";
        echo "<p>basename(dirname(FILE)): " . basename(dirname(__FILE__)) . "</p>";

And when I call getPageInfo( ) from “/account/profile.php” I am getting the script name and location of where the function is located instead of the calling script.

How can I fix this?

Maybe?

<?php
$page = $_SERVER['REQUEST_URI'];    
function getPageInfo($x){
    echo "<p>basename(FILE): " . basename($x) . "</p>";
    echo "<p>basename(dirname(FILE)): " . basename(dirname($x)) . "</p>";
}
getPageInfo($page);
?>

This seems to work, but maybe there is a better way…

        echo "<p>dirname: " . dirname($_SERVER['SCRIPT_NAME']) . "</p>";
        echo "<p>basename: " . basename($_SERVER['SCRIPT_NAME']) . "</p>";

That’s about the best way you’re gonna have.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.