Page 1 of 1

Current File's Name

Posted: Thu Aug 03, 2006 11:53 am
by tecktalkcm0391
How could I get the file's that is running the codes filename. So if I have a script on include.php, and I include it on main.php and I had the code on include.php it would show up include.php?

Posted: Thu Aug 03, 2006 11:54 am
by Luke
___FILE___ ??

Posted: Thu Aug 03, 2006 12:01 pm
by tecktalkcm0391
OK, well I am really bad at things like this... but how could I make it find the /(whatever).php and then remove everything but the (whatever).php?

Posted: Thu Aug 03, 2006 12:04 pm
by NiGHTFiRE
$_SERVER['PHP_SELF'] ?

From php.net's site:

'PHP_SELF'
The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. included) file.

If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.

Posted: Thu Aug 03, 2006 12:07 pm
by Luke
that should be $_SERVER['PHP_SELF'] if register globals is off...

anyway, PHP_SELF (potentially) can contain user input, so if you use it (which is not recommended), filter it. Another way (I believe) is to do basename(__FILE__)

Posted: Sat Aug 05, 2006 9:01 am
by tecktalkcm0391
Ok, well how would I filter $_SERVER['PHP_SELF']?