Аналог функции для сокетов, только с использованием курла. Постоянно теряю её на харде, поэтому выложу здесь:
<?php
set_time_limit(0);
ob_implicit_flush ();
//
//mr.The
//
/**
Функция получения страницы с использованием курла
**/
function get_page($url,$post='',$ref='',$cookie='',$ua="Opera 9.64 (compatible; MSIE 6.0; Windows NT 5.1; ru)",$proxy='') {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT,$ua);
curl_setopt($ch, CURLOPT_REFERER,$ref);
curl_setopt($ch, CURLOPT_PROXY , $proxy);
if($post!==''){
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$headers [] = "Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1";
$headers [] = "Accept-Language: ru,en;q=0.9,ru-RU;q=0.8";
$headers [] = "Connection: close";
$headers [] = "Cache-Control: no-store, no-cache, must-revalidate";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
@curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
if($result)return $result; else return false;
}
function get_cookie($page) {
if(!preg_match_all("/Set-Cookie: (.*)(; |\n)/Ui",$page,$rnd)) return false;
print_r($rnd);
$co="";
foreach($rnd[1] as $key) $co.=trim($key).";";
return $co;
}
?>