Re: Re: Working directory of PHP pages?

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

 



On Thu, Mar 12, 2009 at 12:47 AM, Clancy <clancy_1@xxxxxxxxxxxx> wrote:
> On Wed, 11 Mar 2009 13:03:19 -0500, haliphax@xxxxxxxxx (haliphax) wrote:
>
>>On Wed, Mar 11, 2009 at 12:44 PM, Shawn McKenzie <nospam@xxxxxxxxxxxxx> wrote:
>>> 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.
>>
>>Come to think of it, this may very well be true for all MVC frameworks
>>(unless the models, views, and controllers are all in the same
>>directory as the launch script). I can at least vouch for the fact
>>that CodeIgniter, like CakePHP, will fudge your directory estimation
>>if you're expecting getcwd() to be right.
>
> Something Stewart said the other day made me realise that there was a fundamental error in
> the way I was thinking about this question. I had been thinking that opendir (.) opened
> the root directory, and that paths such as Joe/Nurg.com were relative to the root
> directory, but I now realise that they are relative to the current directory, whatever
> that might be. (Yes; I should have known better, but there is an awful swamp of burnt out
> brain cells at the bottom of my brain.)
>
> So the question I should have asked was "When a web page is loaded, can I rely on the CWD
> being the directory containing index.php (or whichever file is actually loaded)?"

I believe the answer was "No, not really," from several different people.


-- 
// Todd

-- 
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