mikey_w
January 18, 2015, 10:26pm
1
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?
Drummin
January 18, 2015, 10:37pm
2
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);
?>
mikey_w
January 19, 2015, 12:41am
3
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.
system
Closed
April 20, 2015, 8:06pm
5
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.