【发布时间】:2017-10-22 06:02:47
【问题描述】:
我想多次 cURL 并在它们之间共享 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);
}
?>
但运行代码后,我看不到通过网络浏览器多次请求页面的结果。 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。
【问题讨论】: