php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67743 file_get_contents get some url file error
Submitted: 2014-08-02 02:22 UTC Modified: 2014-08-06 01:17 UTC
From: skadon at 163 dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.4.31 OS: Win32
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: skadon at 163 dot com
New email:
PHP Version: OS:

Further comment on this bug is unnecessary.

 

 [2014-08-02 02:22 UTC] skadon at 163 dot com
Description:
------------
the real is get "http://localhost/", not $url.

Test script:
---------------
$url="http://shjianbang168.1688.com/";
$st=file_get_contents($url);
if ($st){
    file_put_contents("./a.txt", $st); 
    echo "OK";	
}else{
    echo "error"; 
}


Patches

add-fronk-support (last revision 2014-08-02 02:25 UTC by skadon at 163 dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-02 03:07 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2014-08-02 03:07 UTC] requinix@php.net
Not enough information was provided for us to be able
to handle this bug. Please re-read the instructions at
http://bugs.php.net/how-to-report.php

If you can provide more information, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PHP.



 [2014-08-05 15:41 UTC] skadon at 163 dot com
-Status: Feedback +Status: Open
 [2014-08-05 15:41 UTC] skadon at 163 dot com
function  file_get_contents Unable to resolve the domain name such as "abc123.1688.com",it's resolve to 127.0.0.1
 [2014-08-05 17:27 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-08-05 17:27 UTC] requinix@php.net
Then that's your problem: the domain name is resolving to 127.0.0.1. Fix that and it should start working for you.
 [2014-08-06 00:04 UTC] skadon at 163 dot com
D:\Documents and Settings\Administrator>ping shjianbang168.1688.com

Pinging cn.split.1688.com [42.156.140.61] with 32 bytes of data:

Reply from 42.156.140.61: bytes=32 time=35ms TTL=54
Reply from 42.156.140.61: bytes=32 time=30ms TTL=54
Reply from 42.156.140.61: bytes=32 time=36ms TTL=54
Reply from 42.156.140.61: bytes=32 time=36ms TTL=54

Ping statistics for 42.156.140.61:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 30ms, Maximum = 36ms, Average = 34ms
 [2014-08-06 00:15 UTC] skadon at 163 dot com
use "Mozilla Firefox" or "Internet Explorer" view "http://shjianbang168.1688.com/" is ok, 
but use file_get_contents("http://shjianbang168.1688.com/") is not same to the Firefox or IE.
use PHP file_get_contents("http://shjianbang168.1688.com/") is same to "Firefox view http://127.0.0.1/"(I have localhost server, so i can test PHP script)
 [2014-08-06 00:48 UTC] requinix@php.net
Not sure what I can tell you except that if PHP is sending you to 127.0.0.1 then that's because something told it to.

As one more thing to check, see what you get with
  print_r(dns_get_record("shjianbang168.1688.com"));
  print_r(get_headers("http://shjianbang168.1688.com/"));

If that doesn't help then try a mailing list or online forum for more support.
http://php.net/support.php
 [2014-08-06 01:06 UTC] skadon at 163 dot com
my function get_url is use fsockopen, get the content of html is same to IE html code.a1.txt it's OK.

function file_get_contents get content of html is error! 

$url="http://shjianbang168.1688.com/";
$st=file_get_contents($url);
if ($st){
    file_put_contents("./a.txt", $st); 
    echo "OK<br>";	
}else{
    echo "error<br>"; 
}

get_url($header, $st,  "shjianbang168.1688.com", "/");
if ($st){
    file_put_contents("./a2.txt", $st); 
    echo "OK2<br>";	
}else{
    echo "error2<br>"; 
}


  print_r(dns_get_record("shjianbang168.1688.com"));

Array
(
    [0] => Array
        (
            [host] => shjianbang168.1688.com
            [class] => IN
            [ttl] => 600
            [type] => CNAME
            [target] => cn.1688.com
        )

)

  print_r(get_headers("http://shjianbang168.1688.com/"));
Array
(
    [0] => HTTP/1.1 302 Found
    [1] => Date: Wed, 06 Aug 2014 00:58:21 GMT
    [2] => Server: Apache
    [3] => Location: http://127.0.0.1/
    [4] => Vary: Accept-Encoding
    [5] => Content-Length: 201
    [6] => Connection: close
    [7] => Content-Type: text/html; charset=iso-8859-1
    [8] => HTTP/1.1 200 OK
    [9] => Date: Wed, 06 Aug 2014 00:58:12 GMT
    [10] => Server: Apache/2.2.25
    [11] => X-Powered-By: PHP/5.4.31
    [12] => Vary: Accept-Encoding
    [13] => Connection: close
    [14] => Content-Type: text/html
)

function get_url(&$header, &$content, $ahost, $url){
	$header="";	$content="";
	$fp = fsockopen($ahost, 80, $errno, $errstr, 30);
	if ($fp) {
		$out  = "GET $url HTTP/1.1\r\n";
		$out .= "Host: $ahost\r\n";
		$out .= "Referer: http://$ahost/\r\n";
		$out .= "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2;)\r\n";
		//$out .= "Accept-Encoding: gzip,deflate\r\n";
		$out .= "Connection: Close\r\n\r\n";
		fwrite($fp, $out);
		$content="";
		while (!feof($fp)) {
			$content.= fgets($fp);
		}
		fclose($fp);
		$pos=stripos($content, "\r\n\r\n");
		if ($pos>0){
			$header=substr($content, 0, $pos);
			$content=substr($content, $pos+4);
		}
		if (stripos($header, "Transfer-Encoding: chunked")!==false)
			$content=http_chunked_decode($content);
		return true;
	} else {
		$content=false;
		return false;
	}
}
 [2014-08-06 01:17 UTC] requinix@php.net
-Block user comment: No +Block user comment: Yes
 [2014-08-06 01:17 UTC] requinix@php.net
The get_headers() output shows that PHP is being redirected to 127.0.0.1. Why? You'd have to ask them.

So not a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 13:01:30 2024 UTC