为什么 PHP 服务器在 include() 和 required_once() 函数上显示错误?
Why PHP Server showing error on include() and required_once() functions?
我在我的站点中使用包含的 php 页面,它在本地主机中完美无误地工作,但是在 运行 使用实时网络服务器时它显示错误。
使用这些功能
include("http-url/file.php")
和 required_once("http-url/file.php")
他们显示这样的错误
Warning: include(): http:// wrapper is disabled in the server
configuration by allow_url_include=0 in
www.mysite.com/....
with file inclution.........
what to do to solve this issue
许多开发人员通过指向远程 URL 来包含文件,即使文件在本地系统中也是如此。例如:
<?php include("http://example.com/includes/example_include.php"); ?>
禁用allow_url_include后,此方法无效。相反,该文件必须包含在本地路径中,可以通过三种方法实现:
- 通过使用相对路径,例如../includes/example_include.php.
- 通过使用绝对路径(也称为相对根目录),例如 /home/username/example.com/includes/example_include.php.
- 通过使用PHP环境变量$_SERVER['DOCUMENT_ROOT'],其中returnsweb根目录的绝对路径。这是迄今为止最好的(也是最便携的)解决方案。以下示例显示了环境变量的作用。
示例包括
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/example_include.php"); ?>
更多关于 allow_url_include here
我在我的站点中使用包含的 php 页面,它在本地主机中完美无误地工作,但是在 运行 使用实时网络服务器时它显示错误。
使用这些功能
include("http-url/file.php")
和 required_once("http-url/file.php")
他们显示这样的错误
Warning: include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in www.mysite.com/.... with file inclution......... what to do to solve this issue
许多开发人员通过指向远程 URL 来包含文件,即使文件在本地系统中也是如此。例如:
<?php include("http://example.com/includes/example_include.php"); ?>
禁用allow_url_include后,此方法无效。相反,该文件必须包含在本地路径中,可以通过三种方法实现:
- 通过使用相对路径,例如../includes/example_include.php.
- 通过使用绝对路径(也称为相对根目录),例如 /home/username/example.com/includes/example_include.php.
- 通过使用PHP环境变量$_SERVER['DOCUMENT_ROOT'],其中returnsweb根目录的绝对路径。这是迄今为止最好的(也是最便携的)解决方案。以下示例显示了环境变量的作用。
示例包括
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/example_include.php"); ?>
更多关于 allow_url_include here