Page 1 of 1

How to Extract the filename of the current Document?

Posted: Sun Jan 08, 2006 11:46 pm
by kearns
Hi, good day ...

I just want to ask how to extract a filename of the current document ? As of now, im building a php driven site and dont know how to extracty the filename of the current document im doing.

Here is the algorithm :

Example:

template.php - it will call an external php page called affad.php

affad.php - this will hold the code that will determine the category where the output appears base on the filename

My focus is how to extract the filename of the curent documant ...

Any help is deeply appreciated :

Thanks ...

Posted: Mon Jan 09, 2006 12:21 am
by hawleyjr
mayhaps: __FILE__ ???

Posted: Mon Jan 09, 2006 12:39 am
by feyd
__FILE__ is literally, the file where that text appears. It sounds like you want to know what script was called by the client. Have a look through $_SERVER, since the fields filled varies slightly from server to server. Fields that can exist and will contain the filename are (but not limited to) SCRIPT_NAME, PHP_SELF, REQUEST_URI

Posted: Mon Jan 09, 2006 2:48 am
by Jenk
as feyd suggests, sounds like $_SERVER contains what you are after, in partciular $_SERVER['SCRIPT_NAME']

but do be warned, some of the fields in $_SERVER can be tainted unwantedly by the user - $_SERVER['PHP_SELF'] is one, as has been shown in a previous thread.

Posted: Mon Jan 09, 2006 7:18 am
by s.dot
If you just want the script of the corrent document, something like $_SERVER['PHP_SELF'] would suffice.

However if the document you want the URI of has a query string appended to it then you will need to request the query string from $_SERVER['QUERY_STRING'] and append it to the result of php_self

Posted: Mon Jan 09, 2006 9:56 am
by pickle
scrotaye wrote:If you just want the script of the corrent document, something like $_SERVER['PHP_SELF'] would suffice.

However if the document you want the URI of has a query string appended to it then you will need to request the query string from $_SERVER['QUERY_STRING'] and append it to the result of php_self
$_SERVER['REQUEST_URI'] does that for you.