[英]PHP cURL cookies not maintaining
我想多次卷曲一個地址並在它們之間共享cookie文件。 我使用的代碼如下所示:
<?php
$count = $argv[1];
echo $count;
while($count > 0){
$ch = curl_init("somewhere.php");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, "./cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "./cookeis.txt");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
$count--;
echo $count;
// grab URL and pass it to the browser
echo curl_exec($ch) . "\n\n";
// close cURL resource, and free up system resources
curl_close($ch);
}
?>
但是運行代碼后,我看不到通過Web瀏覽器多次請求頁面的結果。 雖然cookie文件已填充。
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
somewhere FALSE / FALSE 0 PHPSESSID something
錯誤在哪里? TG。
我發現了錯誤。 這些代碼行應已添加:
...
$cookie = session_name() . '=' . time();
...
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
...
TG。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.