Reputation: 1320
Hello I wonna use curl_multi_init(), first to login to a website and grab that cookie, and then use it at the next site, still with curl_multi_init().
i have been googling a while for this and tryed many different things. i got thise code now, but it aint using the cookie second time.
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);
Upvotes: 0
Views: 638
Reputation: 5556
You must use synchronous requests, because you want to execute your requests in particular order. cURL multi causes it downloads both pages in same time (or second request is done before first one). Second request must be executed after the first will finish.
Upvotes: 2