Bypassing URL file-access is disabled

For some odd reason this host has disabled URL file-access.
So i needed something simple to bypass this problem:

function fetch_url($url)
{
    if (preg_match("#^http://(.*?)/(.*)$#", $url, $matches))
    {
        $host = $matches[1];
        $uri = $matches[2];
        $msg = "GET /$uri HTTP/1.0\r\nHost: $host\r\n\r\n";

        $fp = fsockopen($host, 80, $errno, $errstr, 10);
        fwrite($fp, $msg);
        $ignore = true;
        while (!feof($fp))
        {
            $read = fgets($fp, 1024);
            if (!$ignore)
            {
                $contents .= $read;
            }
            if (preg_match("#^Content-Type: .*?\r\n$#", $read))
            {
                $ignore = false;
            }
        }
        fclose($fp);
        return $contents;
    }
}

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>