NYCPHP Meetup

NYPHP.org

[nycphp-talk] How do you do the equivalent of $PHP_SELF for PHP scripts not in docroot?

Andrew Yochum andrew at digitalpulp.com
Tue May 18 12:36:15 EDT 2004


On Tue, May 18, 2004 at 12:13:47PM -0400, Phillip Powell wrote:
> Is there a way to get an equivalent of $PHP_SELF for a PHP script that 
> is not residing in the document root?  Apparently if you have PHP 4.3.2 
> and Apache 2.0 in Red Hat Linux 7.3, at the very least, $PHP_SELF is 
> only populated with content indicating the location of the PHP script 
> calling $PHP_SELF if that PHP script resides in Apache's document root 
> or below.
> 
> But I have some PHP scripts that will be ultimately referenced via cron 
> that have to reside outside of the document root.  When I do
> 
> [PHP]phpinfo();[/PHP]
> 
> I get "no value" for the variable $PHP_SELF.  This tells me apparently 
> that it can only identify itself from within the document root. 
> 
> So this leaves me with a problem.  How can I find $PHP_SELF, or 
> something like $PHP_SELF, in a PHP script that's outside of the document 
> root?  I am looking for values within the path that I will need to 
> dynamically populate portions of that same PHP script, otherwise, the 
> user, upon inheriting these cron files, have to MANUALLY change values 
> inside the PHP script every time!

Try the __FILE__ constant.  Example:
    echo __FILE__;

HTH,
Andrew



More information about the talk mailing list