Base Directory?!

Posted on March 15th, 2007 in Coding by abdallah

For a while now I used something like the following to get a good include() path for my PHP code.

[ php Code ]
  1. if (!defined("BASE_PATH")) define(‘BASE_PATH’, $_SERVER[‘DOCUMENT_ROOT’].‘/mrp’));
  2. require_once(BASE_PATH."/config/cn.php");

However, I was hit with the realization that it won’t work with my new Apache setup, which goes something like the following:

[ conf Code ]
  1. ServerRoot "X:/home/abdallah/xampplite/apache"
  2. DocumentRoot "X:/home/abdallah/xampplite/htdocs"
  3. <ifmodule>
  4.      Alias /mrp "X:varwwwmanufac"
  5. </ifmodule>
  6. <directory>
  7.     AllowOverride None
  8.     Options all
  9.     Order allow,deny
  10.     Allow from all
  11. </directory>

So, $_SERVER['DOCUMENT_ROOT'] no longer works!
Instead I’ve reverted to something like the following:

[ php Code ]
  1. if (!defined("BASE_PATH")) define(‘BASE_PATH’, substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), ‘mrp’)+3));

Post a comment

You must be logged in to post a comment.