$ckfile = tempnam ("/tmp", "CURLCOOKIE");
$useragent="Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16";
$ch = curl_init ("website.com");
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec ($ch);
The website sets a cookie and then redirects. Would this code suffice? Because it seems to be not getting the cookie properly. How can I check to see if it’s set? Better yet, if I know what cookies I want can I just make it or something?
Edit: So my CURL script visits the website right? The website sets cookies for validation, and I want to see if my cURL script is receiving those cookies properly. I want to know if there’s a test for that, and/or I want to know if I can just create a cookie to validate for the website.
I recently had a project where I needed to pass cookies between servers, and I found that setting both
CURLOPT_COOKIEFILEandCURLOPT_COOKIEJARto the same file did the trick.If you’re just wanting to see if the cookies from the remote site are being set, you should be able to look at the
CURLOPT_COOKIEJARfile in a text editor.