guttyguppy Posted January 8, 2010 Share Posted January 8, 2010 Here's my code: $curDir=getcwd(); $docRoot=$_SERVER['DOCUMENT_ROOT']; echo "current dir is:".$curDir; echo "<br/>"; echo "doc root is:".$docRoot; I'm getting : current dir is:/home/username/public_html doc root is:/var/www/ Why aren't those the same thing? I am having a really hard time understanding server environments, directory paths, so if you can forward any enlightening tutorials/explainations, it would be greatly appreciated. I've checked php.net, but I still don't get it. Thanks! Quote Link to comment Share on other sites More sharing options...
Catfish Posted January 9, 2010 Share Posted January 9, 2010 cwd is the current working directory and DOCUMENT_ROOT is: The document root directory under which the current script is executing, as defined in the server's configuration file. See: http://www.php.net/manual/en/reserved.variables.server.php The current working directory changes depending on what's going on. If you are calling: www.yoursite.com/index.php the cwd would be something like what you said "/home/username/public_html" if you executed the same script in a sub-directory: www.yoursite.com/subDirectory/index.php the cwd would now be "/home/username/public_html/subDirectory" but DOCUMENT_ROOT would not change because it is what it says above. You can change the current working directory in your scripts too, using functions like chdir() http://au2.php.net/manual/en/function.chdir.php Quote Link to comment Share on other sites More sharing options...
guttyguppy Posted January 18, 2010 Author Share Posted January 18, 2010 Thanks Catfish, that helps. I'm still confused as to why they are different at the begginning; shouldn't they both be var or home? Quote Link to comment Share on other sites More sharing options...
Catfish Posted January 18, 2010 Share Posted January 18, 2010 i think it depends on how the server is set up, and probably how the httpd server is configured. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.