Solution:1
You could set cookie through the CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE options of curl in PHP. Example:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFilePath);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFilePath);
$rsp = curl_exec($ch);
curl_close($ch);
Then the cookie content will be automatically saved in the $cookieFilePath, which is a local file path.