cURL Mailing List Monthly Index Single Mail
Re: curl, php, and cookies
From: David Colter <dolan2go_at_yahoo.com>
Date: Fri, 23 Dec 2011 18:52:14 -0500
I can understand your *grumble*. I've been there before, too and still occasionally it happens. The php page for curl_setopt has much info, but leaves much unsaid.
> How does one then get cookies into the cookie file when the local script is setting the cookies? The other thing I have noticed is that occasionally cURL seems to want to delete cookies from the cookie file if they were not set in the headers, keeping only those that were set. How then to keep those cookies in the cookie file?
Look at the curlopt_cookie. Example: curl_setopt($ch, CURLOPT_COOKIE, 'user=ellen; activity=swimming'); In the past, I used that (infrequently now) after parsing the cookie from a previous page, sending it back to the site with this curl option and later deleting this 'additional' cookie. I though it was like having to prime the pump to get curl to work. cURL does a good job with the cookies in my experience.
In some of my programs, there are many (10+) curl_exec that are used to replicate the browser headers step by step (page by page) Sometimes the followlocation option can consolidate steps, other times I use simply (and with trial & error) attempt to make curl verbose output be the same as within the browser.
Another idea is to take the building block approach. Work on the code one page at a time through getting logged in. Ask curl to echo $page (=curl_exec($ch)) until you become more proficient.
Best wishes. Happy Holidays.
These mail archives are generated by hypermail.
Page updated November 12, 2010.
web site info