I'll be honest, I've never once used COOKIEJAR or COOKIEFILE, I've always just set the cookie header. You could try reading the return headers and setting the cookie header manually. here's an example of sending my session cookie back to my website.
$ch = curl_init('https://derokorian.com');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
// We need to get headers back in our response
CURLOPT_HEADER => true,
]);
$result = curl_exec($ch);
// Check that the request was successful
if ($result === false) {
die(sprintf("cURL failed (%d): %s\n", curl_errno($ch), curl_error($ch)));
}
// Get the session cookie out of the response
if (preg_match_all("/^Set-Cookie: DFW_SESSION=([^;]*)/mi", $result, $matches)) {
$sessId = $matches[1][0];
} else {
die("No session cookies found in response\n");
}
// Make a new request, this time sending in the session cookie
$ch = curl_init('https://derokorian.com');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
// Get headers again, to prove out that the cookie was successfully sent
CURLOPT_HEADER => true,
// You can either use CURLOPT_COOKIE like this or...
CURLOPT_COOKIE => 'DFW_SESSION='.$sessId
// You can use CURLOPT_HTTPHEADER like this
CURLOPT_HTTPHEADER => [
'Cookie: DFW_SESSION='.$sessId
]
]);
$result = curl_exec($ch);
// Look at the result, as you can now see, there is no longer a set-cookie in the response, because the correct session was already sent in
var_dump($result);