note 97962 added to function.fsockopen
| From: | SoupNazi at osu1 dot php dot net | Date: | Tue, 18 May 2010 18:58:28 +0000 |
| Subject: | note 97962 added to function.fsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169375@lists.php.net to get a copy of this message | ||
I would like to save people some time. I spent a couple hours trying to de-hunkify the response
from apache2. I found out that if you simply make a 1.0 request vs. a 1.1 request you will get no
hunks and so this simple script below will get the page you want in plain text, no hunks:
<?php
$data=false;
$url='www.example.com';
$fp = @fsockopen($url, 80, $errno, $errstr, 1);
if ($fp) {
stream_set_timeout($fp,1);
$out = "GET / HTTP/1.0\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";
if (fwrite($fp, $out)) {
$content='';
$header = "not yet";
while (!feof($fp)) {
$data=true;
$line=fgets($fp,128);
if ($line=="\r\n" && $header=="not yet") {
$header = "passed";
}
if ($header=="passed") {
$content.=$line;
}
}
fclose ($fp);
}
}
if (!$data) {
print "Unable to retrieve all or part of $url";
} else {
print "$content";
}
?>
I borrowed some of the script from another poster here - the portion removing the returned header.
----
Server IP: 64.71.164.2
Probable Submitter: 70.63.37.154
----
Manual Page -- http://www.php.net/manual/en/function.fsockopen.php
Edit -- https://master.php.net/note/edit/97962
Del: integrated -- https://master.php.net/note/delete/97962/integrated
Del: useless -- https://master.php.net/note/delete/97962/useless
Del: bad code -- https://master.php.net/note/delete/97962/bad+code
Del: spam -- https://master.php.net/note/delete/97962/spam
Del: non-english -- https://master.php.net/note/delete/97962/non-english
Del: in docs -- https://master.php.net/note/delete/97962/in+docs
Del: other reasons-- https://master.php.net/note/delete/97962
Reject -- https://master.php.net/note/reject/97962
Search -- https://master.php.net/manage/user-notes.php