note 66068 added to function.fsockopen
| From: | airlover at gmail dot com | Date: | Sat, 13 May 2006 19:07:41 +0000 |
| Subject: | note 66068 added to function.fsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111240@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 194.153.94.10
Probable Submitter: 143.248.241.143
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.fsockopen.php
Edit -- http://master.php.net/note/edit/66068
Del: integrated -- http://master.php.net/note/delete/66068/integrated
Del: useless -- http://master.php.net/note/delete/66068/useless
Del: bad code -- http://master.php.net/note/delete/66068/bad+code
Del: spam -- http://master.php.net/note/delete/66068/spam
Del: non-english -- http://master.php.net/note/delete/66068/non-english
Del: in docs -- http://master.php.net/note/delete/66068/in+docs
Del: other reasons-- http://master.php.net/note/delete/66068
Reject -- http://master.php.net/note/reject/66068
Search -- http://master.php.net/manage/user-notes.php