2

I am using php-5.6.30 and Apache 2.2.15 on Centos. I am using this code:

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

I am accessing it like : http://10.20.30.40:8001/index.html?uri="URL HERE" Whenever I am using URL like http://www.example.com then it is working fine. But whenever I use URL like http://127.0.0.1:8000/App/app.html or http://10.10.10.40:9000/App/app.html it is returning bool(false).

When I am running the same code(above code) on Windows WampServer(Apache 2.4.18 - PHP 5.6.19 - MySQL 5.7.11) and accessing it . It is working fine. But when I am using the same code with Centos(Apache 2.2.15, php-5.6.17-3(cli) it is not working .

Anubhav Singh
  • 432
  • 1
  • 5
  • 15

3 Answers3

2

It could be that the SELinux settings for httpd prohibit some outbound connections. Try checking the following setting:

$ getsebool httpd_can_network_connect
httpd_can_network_connect --> off

If it is set to off, try enabling it:

$ sudo setsebool -P httpd_can_network_connect on
$ getsebool httpd_can_network_connect
httpd_can_network_connect --> on

Now your httpd server should be able to make outgoing connections. I'm not exactly sure why it already could connect to http://www.example.com, but not localhost, but this fixes the same problem on my system.

Although this will likely fix your problem, be careful about changing this and other settings. There might be unforeseen security implications so you should vet this solution before using it in production.

You can see all of the settings that affect httpd:

$ getsebool -a | grep httpd
mhawke
  • 84,695
  • 9
  • 117
  • 138
0

Use cURL instead of of file_get_contents. This link would be useful PHP : How to use curl instead file_get_contents?

Community
  • 1
  • 1
aslantorret
  • 273
  • 4
  • 10
0
$query = http_build_query(urldecode($_REQUEST['url']));

and also you can check allow_url_fopen in php.ini file.

or you can also use curl instead of file_get_contents.

Mostafa Norzade
  • 1,578
  • 5
  • 24
  • 40