note 99243 deleted from function.fsockopen by danbrown
| From: | danbrown@php.net | Date: | Thu, 05 Aug 2010 15:16:37 +0000 |
| Subject: | note 99243 deleted from function.fsockopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171406@lists.php.net to get a copy of this message | ||
Note Submitter: Stalingraddd at gmail dot com
Reason: non-english
----
<?php
set_time_limit(0);
ob_implicit_flush();
//
//mr.The (C)
//
/**
ФÑнкÑÐ¸Ñ Ð¿Ð¾Ð»ÑÑÐµÐ½Ð¸Ñ ÑÑÑаниÑÑ
Ñ Ð¸ÑполÑзованием ÑокеÑов
**/
function get_page($site, $page, $ref = '', $cookie = '',
$post = '', $isheaders = false, $ua = 'Opera 9.27 (compatible;
MSIE 6.0; Windows NT 5.1; ru)')
{
$page =trim($page);
$site =trim($site);
$socket=fsockopen($site, 80, $errno, $errstr, 15);
if ($socket)
{
if ($post != '')
{
$send="POST $page HTTP/1.0\r\n";
$send.="Content-Length: " . strlen($post) . "\r\n";
$send.="Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n";
}
else
$send="GET $page HTTP/1.0\r\n";
$send.="User-Agent: $ua\r\n";
$send.="Host: $site\r\n";
$send
.="Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png,
image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1\r\n";
if ($ref != '')
$send.="Referer: $ref\r\n";
if ($cookie != '')
{
$send.="Cookie: $cookie\r\n";
$send.='Cookie2: $Version=1' . "\r\n";
}
$send.="Accept-Language: ru,en;q=0.9,ru-RU;q=0.8\r\n";
$send.="Connection: close\r\n\r\n" . $post;
if (fputs($socket, $send))
{
if (!$isheaders)
while (fgets($socket, 1024) != "\r\n" && !feof($socket));
$he="";
while (!feof($socket)) {
$he.=fread($socket, 10240);
$stream_meta_data = stream_get_meta_data($socket);
if($stream_meta_data['unread_bytes'] <= 0) break; }
}
fclose($socket);
}
return $he;
}
?>