file_get_contents($ url)返回bool(false)

时间:2017-02-23 08:45:21

标签: php file-get-contents

我在Centos上使用php-5.6.30和Apache 2.2.15。我正在使用此代码:

 $uri = trim(urldecode($_REQUEST['uri']));
 $validate_content = @file_get_contents($uri);
 echo $validate_content;

我正在访问它:http://10.20.30.40:8001/index.html?uri=“URL HERE” 每当我使用http://www.example.com之类的网址时,它都能正常运行。但每当我使用http://127.0.0.1:8000/App/app.htmlhttp://10.10.10.40:9000/App/app.html之类的网址时,它都会返回bool(false)。

当我在Windows WampServer(Apache 2.4.18 - PHP 5.6.19 - MySQL 5.7.11)上运行相同的代码(上面的代码)并访问它时。它工作正常。但是当我使用与Centos相同的代码(Apache 2.2.15,php-5.6.17-3(cli)时,它无效。

2 个答案:

答案 0 :(得分:0)

使用cURL而不是file_get_contents。此链接非常有用PHP : How to use curl instead file_get_contents?

答案 1 :(得分:0)

$ query = http_build_query(urldecode($ _ REQUEST [' url']));

你也可以在php ini文件中查看allow_url_fopen。

或者您也可以使用curl而不是file_get_contents

相关问题