How can you display a scripts own file name without hardcoding it?
How to display its own file name
You can try...
echo $GLOBALS[PHP_SELF];
or
echo $_SERVER[SCRIPT_FILENAME];
You'll need to do a string replace to get exactly what you want.
If you ever want to see what's happening behind the scenes with these variables... try pasting this at the end of your script. I keep this in it's own file and include as necessary for debugging.
function myinfo($array)
{
echo "<pre>";
print_r($array);
echo "</pre>";
}
myinfo($GLOBALS);
myinfo($_SESSION);
Cheers,
TS
FILE holds the current files name, even if it's included it'll give you the name of the file it's used in. The above $SERVER['SCRIPT_FILENAME'] will give you the name of the running script even if called in an include. $SERVER['SCRIPT_NAME'] gives you the name of the running script relative to the domain you're viewing on (if using a browser) and is good do use in forms on self submitting scripts, e.g.
<form name="catsync" action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="POST">
<?php
sync_categories($db, $rDB);
?>
<div align="center"><input type="Submit" name="whatever" value="Synch Those Things" /></div>
</form>
5 days later
Sorry for my late response but thanks both of you.