Hi, I'm just experimenting with cURL and how it handles cookies. I've been trying to get it to write cookies to a file but without success, using some example code (changed slightly) from the book 'Webbots, Spiders and Screenscrapers' by Michael Schrenk. Here is the code : <?PHP $s = curl_init(); $target = "http://www.google.com"; $cookie_file = "c:\temp\phpcookies.txt"; curl_setopt($s, CURLOPT_COOKIEFILE, $cookie_file); // Read cookie file curl_setopt($s, CURLOPT_COOKIEJAR, $cookie_file); // Write cookie file //Configure the cURL command curl_setopt($s, CURLOPT_URL, $target); // Define target site curl_setopt($s, CURLOPT_RETURNTRANSFER, TRUE); // Return in string # Indicate that there is no local SSL certificate curl_setopt($s, CURLOPT_SSL_VERIFYPEER, FALSE); // No certificate curl_setopt($s, CURLOPT_FOLLOWLOCATION, TRUE); // Follow redirections curl_setopt($s, CURLOPT_MAXREDIRS, 4); // Limit redirections to four # Execute the cURL command (Send contents of target web page to string) $downloaded_page = curl_exec($s); print $downloaded_page; # Close PHP/CURL session curl_close($s); ?> PHP: Unfortunately no file containing the cookies appears in 'C:\temp' on my laptop. By the way I'm using an local XAMPP installation to try these scripts. Anyone give me any suggestions ?
I'm not at all familiar with curl, but maybe try these things (yes, some are obvious and makes it sound like I think you're an idiot, but I don't ): --> try adding a backslash to the $cookie_file var, before the c: - this seems necessary sometimes, so maybe here --> try creating that file in advance, and see if the data appears in it, if so then it just isn't creating the file --> I doubt you're not doing this, but refresh the folder after it runs, before looking for the file --> try using a different folder, in case there's something about the folder that stops it working