Re: Working directory of PHP pages?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux