note 66068 deleted from function.fsockopen by bjori
| From: | bjori@php.net | Date: | Sat, 13 May 2006 20:53:43 +0000 |
| Subject: | note 66068 deleted from function.fsockopen by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-111243@lists.php.net to get a copy of this message | ||
Note Submitter: airlover at gmail dot com
Reason: bad code
----
simple wget imitation..
<?
function wget($url, $fn) {
$url_parsed = parse_url($url);
$host = $url_parsed["host"];
$port = $url_parsed["port"];
if ($port==0) $port = 80;
$path = $url_parsed["path"];
if (empty($path)) $path="/";
if ($url_parsed["query"] != "")
$path .= "?".$url_parsed["query"];
$out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";
if (!$fp = @fsockopen($host, $port, $errno, $errstr, 10)) return false;
fwrite($fp, $out);
while (!feof($fp)) {
$line = fgets ($fp,1024);
if (strpos($line, "\r\n", 0) == 0) break;
if (stristr($line,"location:")!="")
return wget(trim(preg_replace("/location:/i","",$line)), $fn);
}
$fh = @fopen($fn, "w");
if (!$fh) return false;
while (!feof($fp)) {
$line = fgets ($fp,1024);
fwrite($fh, $line);
}
fclose($fh);
fclose($fp);
return 0;
}
?>