简体   繁体   中英

Is it prefered to use $_SERVER['DOCUMENT_ROOT'] in the website?

Do you think it is preferred to use $_SERVER['DOCUMENT_ROOT'] in website's include statements? Is it supported everywhere without any problem?

Many frameworks use dirname(__FILE__) to work out the application path based on a known file, usually the index.php

In the Zend Framework, they use the following to define the application path, which is then used everywhere in the app:

define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application');

I personally prefer relative paths: include("../../some/other/path.php") Whenever I create a directory, I know exactly how my directory tree is setup, and it doesn't matter whether there is a document root or anything else available.

Furthermore, there are some cases where $_SERVER['DOCUMENT_ROOT'] may not work (eg, I have seen people have issues with it on IIS).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM