Author Topic: file_get_contents local file issue  (Read 5871 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
file_get_contents local file issue
« on: May 06, 2020, 03:35:32 PM »
Dear Sir,

I got issue and would like to seek help from your side.

I find a interest things when I use file_get_contents and curl to get content from local domain/file hosted on my site.
Example: http://xxx.xxx/index.html
It will have the following error.
 [proxy_fcgi:error] [pid] [client] AH01071: Got error 'PHP message: PHP Warning: file_get_contents(http://xxx.xxx/index.html): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found\r in /home/xxx/public_html/xxx.xxx/xxx.php on line 3'

Tried rebuild apache-->FPM and php5.5 but still not work.

Please help.

Thanks.

Offline
*
Re: file_get_contents local file issue
« Reply #1 on: May 06, 2020, 03:49:04 PM »
More information:
allow_url_fopen=ON
allow_url_include=ON

And PHP will something redirect to http://xxx.xxx/login.htm

Intesting thing is
[root@CWP ~]# find / -name login.htm
It is nothing to find.

Offline
****
Re: file_get_contents local file issue
« Reply #2 on: May 06, 2020, 09:18:11 PM »
If Apache, check .htaccess files for redirects.
If nginx check config file for redirects.

As to the issue of "failed to open stream", have you tried with csf off to see if the issue persists?
Google Hangouts:  rcschaff82@gmail.com

Offline
*
Re: file_get_contents local file issue
« Reply #3 on: May 07, 2020, 09:49:33 AM »
Found the reason.
As my CWP is NAT-ed configuration, PHP (version 5 to 7) seems use the external IP to query the hosted domain.
When I add the internal IP and match hosted domain in /etc/hosts
PHP can find correct correct file now.

Please see if it is bug or CentOS issue.

Thanks.

Offline
****
Re: file_get_contents local file issue
« Reply #4 on: May 07, 2020, 01:19:56 PM »
It's neither.  DNS worked exactly as expected when using the FQDN.  Your machine looked up the IP address of the domain, and it returns the Public IP.  Your issue is with the way NAT works, which is exactly what it is also supposed to be doing.   

So your solution of adding the domains to the hosts file is a great workaround.  The other one can be found here:
Code: [Select]
https://www.the-art-of-web.com/system/iptables-nat/
Google Hangouts:  rcschaff82@gmail.com