|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-02-11 01:59 UTC] mike-bugs dot php dot net at webheat dot co dot uk
Description: ------------ A script I created ( http://webheat.co.uk/forumbuddy.php ) takes a username for the site DeviantArt.com which forms parts of the user's section of the site. The url takes the form of: http://USERID.deviantart.com/ The script grabs one or more pages by using the file_get_contents() function. Regardless of whether I use urlencode()/rawurlencode() and urldecode() the file_get_contents() function chokes with the error as detailed below. This only happens when the userid ends in a hypen. After some testing it seems to be that this is because the hyphen is then next to a period "-." This hyphen period combination causes an error regardless of where it is placed in the user id. This issue happens on my host's server but not on two other [Windows] machines I've tested this code on. The hosting company have gone through their php.ini file on my behalf and whilst the file is not vanilla there are no differences that they can see would affect this fuction. Reproduce code: --------------- The relevant code is as follows: file_get_contents("http://emdeeuk-.deviantart.com"); //Doesn't work file_get_contents("http://emdee-.uk.deviantart.com"); //Doesn't work file_get_contents("http://emdeeuk.deviantart.com"); //Does work The full code can be viewed here: http://webheat.co.uk/forumbuddytest.php.txt Expected result: ---------------- <a href="http://www.deviantart.com/deviation/14935843/">Dogs on Kites</a> <a href="http://www.deviantart.com/deviation/14935312/">Welcome to the Rat Race</a> <a href="http://www.deviantart.com/deviation/14934730/">Arc de Bishopsgate</a> <a href="http://www.deviantart.com/deviation/14592356/">PLEASE VOTE: New Webheat.co.uk</a> <a href="http://www.deviantart.com/deviation/14586143/">Docklands Sunbathing</a> <a href="http://www.deviantart.com/deviation/14556463/">Slide PSP8 Frame</a> <a href="http://www.deviantart.com/deviation/14556193/">Whitechapel Horse</a> <a href="http://www.deviantart.com/deviation/14521593/">Action Squirrel</a> <a href="http://www.deviantart.com/deviation/14520802/">Beady Eye of the Plottin Drake</a> <a href="http://www.deviantart.com/deviation/14485015/">Light House II</a> <a href="http://www.deviantart.com/deviation/14377961/">Polaroid Photo Frames</a> <a href="http://www.deviantart.com/deviation/14217085/">Now where's the Sphinx?</a> <a href="http://www.deviantart.com/deviation/14213953/">Something in the Aer</a> <a href="http://www.deviantart.com/deviation/14125157/">I Sea Gulls</a> <a href="http://www.deviantart.com/deviation/14124660/">Coots really get my Goose</a> <a href="http://www.deviantart.com/deviation/13932181/">Spoonful of sugar</a> <a href="http://www.deviantart.com/deviation/13757002/">Ugly Emotion</a> <a href="http://www.deviantart.com/deviation/13729717/">Light House</a> <a href="http://www.deviantart.com/deviation/13729376/">Ilm Tree</a> <a href="http://www.deviantart.com/deviation/13705596/">Only ugly on the inside</a> <a href="http://www.deviantart.com/deviation/13639781/">Lava Lamponians</a> <a href="http://www.deviantart.com/deviation/13597782/">Generations</a> <a href="http://www.deviantart.com/deviation/9434166/">Flame Mobile Wallpaper</a> <a href="http://www.deviantart.com/deviation/9421010/">Flame Body Work Wallpaper</a> Actual result: -------------- Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/webheat/public_html/forumbuddytest.php on line 6 Warning: file_get_contents(http://USER-.deviantart.com/gallery/?view=3&order=5&limit=24&offset=0): failed to open stream: Permission denied in /home/webheat/public_html/forumbuddytest.php on line 6 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 23 14:00:02 2025 UTC |
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.Correction: $context = stream_context_create(array('http'=>array('proxy'=>'tcp://dummy.deviantart.com:80'))); Forgot the port number :)