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

本小妞迷上赌 提交于 2019-12-11 04:58:44

问题


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


回答1:


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');



回答2:


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



来源:https://stackoverflow.com/questions/8952896/is-it-prefered-to-use-serverdocument-root-in-the-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!