How can you use the CURLOPT_COOKIE option in Curl to set a cookie in PHP?

To set a cookie in PHP using the CURLOPT_COOKIE option in Curl, you need to pass the cookie string as a value to the CURLOPT_COOKIE option. This allows you to set a specific cookie value in the Curl request headers. This can be useful when making HTTP requests that require certain cookies to be set.

$ch = curl_init();
$url = 'http://example.com/api';
$cookie = 'session_id=12345; user_id=67890'; // set your desired cookie values here

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);

// execute Curl request
$response = curl_exec($ch);

// close Curl session
curl_close($ch);

// handle response as needed