I created a JSON API using PHP and when I access it directly (by the address bar) it is able to read and write cookies in the local browser.
When I use cURL or file_get_contents I can’t read and write cookies to the local machine so I tried using:
curl_setopt($ch, CURLOPT_COOKIE, $_SERVER['HTTP_COOKIE']);
This works fine for reading the cookies but I’m not able to set cookies back to the browser.
The cookies I use are very important (authentication) so I need to get them using the API.
Use cookie jar and share it between your cURL “calls”. Set both
CURLOPT_COOKIEFILEandCURLOPT_COOKIEJARto point to the same file and you do not need to useCURLOPT_COOKIE