Page 1 of 1

cURL store cookie problem

Posted: Tue Jul 17, 2007 9:32 am
by j0hn
I'm trying to get access to some XML data, first t&c have to be agreed which stores a cookie. The next time you go straight to the data as the cookie is sent as part of the request.


I can't get/store the cookie when I click yes (to agree the terms), here's my code

Code: Select all

$url = 'http://banners.willhill.com/xml/viewxml.asp?sport=FB&style=12';
$cookieFile = 'C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\xml-testing\cookies.txt';

$ch = curl_init();    // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);              // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);    // allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_PORT, 80);            //Set the port number
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);


$document = curl_exec($ch);

echo $document;

I have read the documentation at http://www.php.net/curl and have read many threads about cURL and cookies on this site but still don't get it.

Any help (or hints) is much appreciated.

Posted: Tue Jul 17, 2007 10:31 am
by mwasif
I have found auser's comments
When specifing CURLOPT_COOKIEFILE or CURLOPT_COOKIEJAR options, don't forget to "chmod 777" that directory where cookie-file must be created.
Did you read all the user comments on http://www.php.net/curl_setopt?