为什么PHP Server在include()和required_once()函数上显示错误?

时间:2015-08-21 06:25:31

标签: php url webserver

我正在使用我的网站中包含的php页面,它在localhost中完美地工作而没有错误,但在使用实时Web服务器运行时它显示错误。 使用这些功能 include("http-url/file.php")required_once("http-url/file.php") 他们显示这样的错误

  

警告:include():http://在服务器中禁用了包装器   配置by allow_url_include = 0 in   www.mysite.com / ....    与文件包含.........   该怎么做才能解决这个问题

1 个答案:

答案 0 :(得分:1)

许多开发人员通过指向远程URL来包含文件,即使该文件位于本地系统中也是如此。例如:

<?php include("http://example.com/includes/example_include.php"); ?>

禁用allow_url_include后,此方法不起作用。相反,该文件必须包含在本地路径中,并且有三种方法可以执行此操作:

  1. 使用相对路径,例如../ includes / example_include.php。
  2. 使用绝对路径(也称为from-from-root),例如/home/username/example.com/includes/example_include.php。
  3. 使用PHP环境变量$ _SERVER [&#39; DOCUMENT_ROOT&#39;],它返回Web根目录的绝对路径。这是迄今为止最好(也是最便携)的解决方案。以下示例显示了正在运行的环境变量。
  4. 示例包含

    <?php include($_SERVER['DOCUMENT_ROOT']."/includes/example_include.php"); ?>
    

    有关 allow_url_include here

    的更多信息