There are various methods of find the path of the
current file in PHP. But the problem is to find one that is consistent
across all servers. The following is a list of the most commonly used
methods to find the location of the current file. The definitions are
taken from the PHP manual(Predefined
Variables) and are modified slightly.
The filename of the
currently executing script, relative to the document root. For
$_SERVER['PHP_SELF']in a script at the address
http://example.com/test.php/foo.bar would be /test.php/foo.bar. The
constant contains the full path and filename of the current (i.e.
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.
query string, if any, via which the page was accessed.
absolute pathname of the currently executing script.
Note: If a script is executed with the CLI, as a relative path, such
as file.php or ../file.php,
will contain the relative path specified by the user.
(not document root-) based path to the current script, after
the server has done any virtual-to-real mapping.
Note: As of PHP 4.3.2, PATH_TRANSLATED is no longer set implicitly
under the Apache 2 SAPI in contrast to the situation in Apache 1, where
it's set to the same value as the
variable when it's not populated by Apache. This change was made to
comply with the CGI specification that
should only exist if
Apache 2 users may use AcceptPathInfo = On inside httpd.conf to
the current script's path. This is useful for pages which need to point
to themselves. The __FILE__ constant contains the full path and
filename of the current (i.e. included) file.
URI used to access this page; for instance,
'/index.html'. Includes the query string.
full path and filename of the file. If used inside an
include, the name of the included file is returned. Since PHP 4.0.2,
always contains an absolute path whereas in older versions it contained
relative path under some circumstances.
|Apache/2.0.52 (Fedora)||PHP 4.3.9||Apache 2.0|
|Apache/2.0.55 (Unix) mod_ssl/2.0.55 OpenSSL/0.9.7a PHP/5.1.4||PHP|
|Apache 2.0 Handler||/test/loc.php||/test/loc.php?hello=world||/var/www/htdocs/test/loc.php||/test/loc.php||hello=world||/var/www/htdocs/test/loc.php|
|Apache/2.0.54 (Unix) PHP/4.4.4 mod_ssl/2.0.54 OpenSSL/0.9.7e|
mod_fastcgi/2.4.2 DAV/2 SVN/1.3.2
If you have access to a server that is not in the above list, please
the below code to generate the results and send the result to me - I
will include it here.