Is there a way to disable/negate the use of $_SERVER['DOCUMENT_ROOT'] when including my php files? I would prefer
require '/somedirectory/somefile.php';
instead of
$_SERVER['DOCUMENT_ROOT'].'/somedirectory/somefile.php';
Running Centos and cPanel.
Or is this something that will always be required when writing my php code?
require './somedirectory/file.php
works from the base of the application without explicitly referring to the $_SERVER ... There is no disabling but there is defining that variable or different variables to aid in your routing. variables like base_url and site_url
The dot refers to the root of the application.
只需使用:
require './somedirectory/somefile.php';
It's not required that you use those. You don't have to use full paths. Apache and PHP will generally look in the same path as the calling file (omit the /
or PHP will think you mean the root of the server drive)
require 'somedirectory/somefile.php';
Another option is to set the include_path so PHP knows where to look implicitly
set_include_path('/full/path/to/files');
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.