Create and place this file in your document root, include it in all other files to easily have access to the directory your site is located without using clumsy and unreliable $_SERVER or $_ENV entries.

_require.php:

<?php
$oldCwd = getcwd();
chdir(dirname(__FILE__));
define('SITE_DOCROOT', getcwd());
chdir($oldCwd);
?>

Related posts:

  1. PHP Dynamic JavaScript SCRIPT Insertion for Embedding
  2. Deployment Using Capistrano / Webistrano via Rails / Phusion Passenger
  3. PHP Sessions on localhost
  4. PHP fast, large (megabyte), data transfer between sessions
  5. PHP jQuery AJAX Javascript Long Polling