Пример формирования Curl-запроса и разбор cookie


$ch = curl_init ("http://www.addurl.driverpack.ru/add.php");
$this_header = array(
"Accept: */*",
"Accept-Language: ru",
"Accept-Encoding: gzip, deflate",
"Cache-Control: max-age=259200",
"Pragma: no-cache",
"Via: 1.0 gsg-server.sitegroup:3129 (squid/2.6.STABLE5)", 
"X-Forwarded-For: 192.168.0.248",
"User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; MRA 4.8 (build 01709))",
"Connection: Keep-Alive");

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $this_header);
//if ($proxy!="")    curl_setopt ($ch, CURLOPT_PROXY, $proxy);
//$browser = get_browser();
//curl_setopt ($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
//curl_setopt ($ch, CURLOPT_POST, 1);
//curl_setopt ($ch, CURLOPT_POSTFIELDS, "user={$_POST['login']}&pass={$_POST['password']}");
$resp = curl_exec ($ch);

if($count = preg_match_all("~Set-Cookie:\s*([^=]+)=([^\s;]+)~si", $resp, $matches))
{
    echo $count.'<br>';
    for ($i=0; $i<$count; $i++)
        echo 'Name: '.$matches[1][$i].' Value='.$matches[2][$i];
}
curl_close ($ch);

.