【问题标题】:PHP cURL cookies not maintainingPHP cURL cookie 不维护
【发布时间】: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。

【问题讨论】:

    标签: php curl cookies


    【解决方案1】:

    我发现了错误。应该已经添加了这些代码行:

    ...
    $cookie = session_name() . '=' . time();
    ...
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    ...
    

    TG。

    【讨论】:

      猜你喜欢
      • 2011-10-08
      • 1970-01-01
      • 2011-10-09
      • 1970-01-01
      • 2010-12-10
      • 2011-07-15
      • 1970-01-01
      • 2015-09-10
      • 2011-12-19
      相关资源
      最近更新 更多