您好 ,我不会使用 curl_multi_init(),首先登录到一个网站并获取该 cookie,然后在下一个站点使用它,仍然使用 curl_multi_init()。
我已经为此搜索了一段时间并尝试了许多不同的东西。我现在得到了这个代码,但它不是第二次使用 cookie。
curl_setopt($login, CURLOPT_HEADER, 0);
curl_setopt($login, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($login, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1284.0 Safari/537.13");
curl_setopt($login, CURLOPT_TIMEOUT, 60);
curl_setopt($login, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($login, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($login, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($login, CURLOPT_REFERER, $loginURL);
curl_setopt ($login, CURLOPT_POSTFIELDS, $postData);
curl_setopt ($login, CURLOPT_POST, 1);
curl_setopt($getByDate, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($getByDate, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1284.0 Safari/537.13");
curl_setopt($getByDate, CURLOPT_TIMEOUT, 60);
curl_setopt($getByDate, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($getByDate, CURLOPT_RETURNTRANSFER, true);
curl_setopt($getByDate, CURLOPT_BINARYTRANSFER, true);
curl_setopt($getByDate, CURLOPT_COOKIEJAR, $cookieFile);
curl_setopt($getByDate, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($getByDate, CURLOPT_REFERER, "https://www.elevplan.dk/Moduler/Elevforside/Elevforside.aspx");
//create the multiple cURL handle
$mh = curl_multi_init();
//add the two handles
curl_multi_add_handle($mh,$login);
curl_multi_add_handle($mh,$getByDate);
$running = null;
do {
curl_multi_exec($mh, $running);
} while ($running);