ID:               31923
 User updated by:  mike-bugs dot php dot net at webheat dot co dot uk
 Reported By:      mike-bugs dot php dot net at webheat dot co dot uk
 Status:           Bogus
 Bug Type:         Filesystem function related
 Operating System: Linux
 PHP Version:      4.3.10
 New Comment:

Thank you for all your help, I'll try this at the weekend most likely.


Previous Comments:
------------------------------------------------------------------------

[2005-02-13 02:23:29] [EMAIL PROTECTED]

Correction:
$context =
stream_context_create(array('http'=>array('proxy'=>'tcp://dummy.deviantart.com:80')));

Forgot the port number :)

------------------------------------------------------------------------

[2005-02-13 02:21:43] [EMAIL PROTECTED]

I have an ugly solution, it's a very rudimentary HTTP/1.0 client which
relies on the fact that deviantart.com uses a wildcard to direct
*.deviantart.com to the same IP address.

It also relies on the fact that they're not doing any kind of 3xx
redirection (at least as far as I could tell).  I wouldn't be surprised
if you need to do some work on this function to make it work *well* for
you.

function http_get_contents($url) {
  $resource = parse_url($url);

  $ip = gethostbyname('dummy.deviantart.com');
  $sock = fsockopen($ip, 80);
  if (!$sock) return false;

  fwrite($sock, "GET {$resource['path']}?{$resource['query']}
HTTP/1.0\r\n");
  fwrite($sock, "Host: {$resource['host']}\r\n");
  fwrite($sock, "Connection: close\r\n\r\n");

  $response = fgets($sock, 8192);
  if (substr($response, 0, 3) != 200) return '';

  /* Skip headers */
  while (trim(fgets($sock, 8192)));

  $ret = '';
  while (!feof($sock)) {
    $ret .= fgets($sock, 8192);
  }

  return $ret;
}


That's PHP4/5 compliant.  If you're only worried about PHP5
compatability you can do:

$context =
stream_context_create(array('http'=>array('proxy'=>'tcp://dummy.deviantart.com')));

$data = file_get_context($url, false, $context);

Which does *essentially* the same thing, but since it's a proper http
wrapper takes care of the 3xx and other shortcommings of the userspace
version I gave you above.

------------------------------------------------------------------------

[2005-02-12 23:24:21] mike-bugs dot php dot net at webheat dot co dot
uk

Thank you Pollita. That's a lot clearer.
Do you have any suggestions for a work around for this issue?

------------------------------------------------------------------------

[2005-02-12 17:52:10] [EMAIL PROTECTED]

"gethostbyname() (Used by the network streams code among other parts of
PHP) treats this correctly according to RFC specification."

I can see this statement being inobvious.  I mean the gehostbyname()
function defined by the host systems standard C library.  You
assumption that PHP's network code does not attempt to validate the
hostname before passing it on to the the system for resolution.  It
works on some systems because on those systems the value is encoded
into a DNS packet and sent to the DNS server unmangled.  On other
systems, a validation check is performed first and if it doesn't pass,
then it doesn't bother waiting for a network round trip, instead simply
returning a failure.

------------------------------------------------------------------------

[2005-02-12 17:17:11] mike-bugs dot php dot net at webheat dot co dot
uk

Thanks Magnus.

This does explain possible behaviour but doesn't explain why 2 Windows
PHP installs work fine but 2 Linux PHP installs (as installed by my
hosting company) do not.

This seems to imply that file_get_contents() doesn't validate the DNS
compliance of the arguement.

Also referring to the previously note from Pollita, as forgiving as the
browser maybe the DNS servers involved in the lookup of
http://mark-.deviantart.com are the ones that are dealing with this
more so from what I know.
The deviantart.com DNS server software also seems to be forgiving, not
just of look ups of this kind but of creating new record of this kind
too, as the DNS entry would have been created when the user mark-
signed up his account with Deviantart.com

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/31923

-- 
Edit this bug report at http://bugs.php.net/?id=31923&edit=1

Reply via email to