不能在php中包含文件

时间:2009-08-07 17:48:07

标签: php

我在一些if / else语句中运行下面的代码,我在同一个文件中有一个奇怪的问题,下面这个确切的代码工作正常,但是在另一个区域,如果它被调用我得到这个错误;

Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\webserver\htdocs\processing\process.friends.php on line 168

Warning: include(http://localhost/index.php) [function.include]: failed to open stream: no suitable wrapper could be found in C:\webserver\htdocs\processing\process.friends.php on line 168

$_SESSION['sess_msg'] = 'Please Enter the Correct Security Code';
$_GET["friendid"] = $friendid;
$_GET["p"] = 'mail.captcha';
$_GET["f"] = 'friend';
include ("index.php");
exit;

只是为了澄清我在同一时间尝试运行此代码2次,它更像是这样;不只是这样,但你明白他们不是同时运行

if(something){
   run the code above
}else{
   run the code above
}

如果重要,我目前正在Windows PC上运行LAMP设置

5 个答案:

答案 0 :(得分:10)

删除代码中的“http://localhost”部分。根据经验,当您包含自己的文件时,应该从文件系统中包含它们。

include "./index.php";

答案 1 :(得分:2)

只需删除 http://localhost/ 部分,您就可以了。

答案 2 :(得分:0)

好吧,我不知道你的问题的答案,但我不得不问你为什么觉得需要包含一个基于URL的文件?

include('http://whatever.com/');可能非常危险。

如果您只是想输出由此生成的HTML,我建议您执行echo file_get_contents('http://some/url');之类的操作。如果您尝试包含PHP代码,请使用系统路径

答案 3 :(得分:0)

他们完全一样吗?你能发布两个版本的代码吗?

我还建议不要做包含('http:// ...');这将使PHP成为对您的Web服务器的HTTP请求,并获取结果。如果可以进行设置,那么你可能会更好地做一下include('index.php');.

答案 4 :(得分:0)

在php.ini中启用了allow_url_fopen吗?