Re: Working directory of PHP pages?

From: Date: Wed, 11 Mar 2009 17:44:27 +0000
Subject: Re: Working directory of PHP pages?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-289872@lists.php.net to get a copy of this message
Clancy wrote: > It is my understanding that when you open a page the PHP server looks for index.php in the > site root directory, and loads it. As a result the working directory of the page will be > the root directory of the site. I have always worked on this assumption, and it has > always been correct. On the other hand Stewart thinks that I cannot rely this, and am > likely to get into trouble as a result. > > Are there any systems in which my assumption will not be correct? > In many frameworks this assumption is not correct. I am using the default CakePHP layout as an example. Depending on your terminology, your DocumentRoot is /var/www/ and in this case is also the filesystem path of your site's root dir, however the sites root dir in a URL is /. Consider the CakePHP structure: /var/www/ .htaccess index.php /var/www/webroot index.php If you browse to http://example.com/ (in most cases), one of 2 things happens: 1. The webserver opens the /var/www/.htaccess and according to the rewrite rules there it rewrites to /var/www/webroot/. So any getcwd() would be /var/www/webroot/ 2. If not using modrewrite, the web server looks for index.html and then index.php in /var/www/ which has a require for webroot/index.php. So any getcwd() would be /var/www/. Consequently, CakePHP and the other frameworks that I've seen use basename() and dirname() in conjunction with __FILE__ to define the paths/relative dirs within the app. -- Thanks! -Shawn http://www.spidean.com

« previous php.general (#289872) next »