2

以下に示すように、curl関数があります。この関数をロードする<img src="http://site.com/pxl.php?i=1.jpg" height="1" width="1" />には、これを使用しますが、そうすると、Cookie がブラウザーに追加されません。URLでcurlが実行されたときに、URLからCookieを収集し、アクセスを使用するブラウザに設定する方法はありますか<img src="http://site.com/pxl.php?i=1.jpg" height="1" width="1" />

function get_content($url,$ref)
{
$browser = $_SERVER['HTTP_USER_AGENT'];
$ch = curl_init();

$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // browsers keep this blank.

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, $browser);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, false);
$html = curl_exec($ch);
curl_close ($ch);
return $html;
}
4

1 に答える 1

-1

cURL を使用してページに Cookie を送信するには、次のCURLOPT_COOKIEオプションを使用します。

curl_setopt($ch, CURLOPT_COOKIE, 'user=alice; activity=knitting');

スクリプトの Cookie を設定するには、setcookie()を使用します。

setcookie("TestCookie", $value, time()+3600); 
于 2013-01-25T05:00:48.393 に答える