
26.01.2009, 22:54
|
|
Познавший АНТИЧАТ
Регистрация: 01.06.2008
Сообщений: 1,047
С нами:
9443906
Репутация:
3313
|
|
Нарыл у себя функцию получения страницы с возможностью работы через http-proxy:
PHP код:
function socket_do($action, $method, $headers, $query = '', $proxy = '')
{
$fp = '';
$head = '';
$action = str_replace('http://', '', $action);
$for_s_conn = substr($action, 0, strpos($action, '/'));
$method = strtoupper($method);
if(!empty($proxy))
{
$ex = explode(':', $proxy);
if(!$fp = @fsockopen($ex['0'], $ex['1'], $errno, $errstr, 15))
die($errstr);
}
else
{
if(!$fp = @fsockopen($for_s_conn, 80, $errno, $errstr, 15))
die($errstr);
}
if($method == 'POST')
{
$head = "POST http://$action HTTP/1.1\r\n";
$head .= "Content-length: ".strlen($query)."\r\n";
}
elseif($method == 'GET')
$head = "GET http://$action HTTP/1.1\r\n";
else
die('Выбран не существующий метод');
$head .= "Connection: close\r\n";
$head .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5\r\n";
$head .= "Host: $for_s_conn\r\n".implode("\r\n", $headers)."\r\n\r\n";
if($method == 'POST')
$head .= $query;
if(@!fwrite($fp, $head))
{
die($errstr);
}
$result = '';
while(!feof($fp))
$result .= @fgets($fp, 8196);
fclose($fp);
return $result;
}
|
|
|