Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么PHP服务器在include()和required_once()函数上显示错误?_Php_Url_Webserver - Fatal编程技术网

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

为什么PHP服务器在include()和required_once()函数上显示错误?,php,url,webserver,Php,Url,Webserver,我正在使用我的站点中包含的php页面,它在localhost中运行良好,没有错误,但在使用live web服务器运行此页面时,它显示了错误。 使用这些函数 include(“http url/file.php”)和required\u一次(“http url/file.php”) 它们是这样的错误 警告:include():http://wrapper在服务器中被禁用 允许的配置\u url\u include=0 www.mysite.com/。。。。 包含文件。。。。。。。。。 如何解决这个

我正在使用我的站点中包含的php页面,它在localhost中运行良好,没有错误,但在使用live web服务器运行此页面时,它显示了错误。 使用这些函数
include(“http url/file.php”)
required\u一次(“http url/file.php”)
它们是这样的错误

警告:include():http://wrapper在服务器中被禁用 允许的配置\u url\u include=0 www.mysite.com/。。。。 包含文件。。。。。。。。。 如何解决这个问题


许多开发人员通过指向远程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环境变量$\u SERVER['DOCUMENT\u ROOT'],它返回web根目录的绝对路径。这是迄今为止最好的(也是最便携的)解决方案。下面的示例显示了正在运行的环境变量
  • 示例包括

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

    关于allow\u url\u include

    的更多信息您是否在
    include
    函数中使用了
    http://
    ?即使这是一项非常具体的任务,并且您需要通过http包含文件,您也会在消息“警告:include():http://在服务器配置中通过allow\u url\u include=0禁用包装器”中看到错误和答案。那么-问题是什么?我正在使用www.mysite1.com中的include,但是包含的文件位于www.mysite2.com中。所以只有我在使用这个http链接……哦,如果你仍然想包含远程文件,你可以设置:allow_url_include=On,但说真的,我建议你不要这样做,因为存在安全风险。不幸的是,上述方法不适用于其他位置的主机。我可以将其与javascript中的document.location一起使用吗