Page 1 of 1

Cookies in php (curl)

Posted: Wed May 28, 2008 9:07 am
by gabiru
Hi guys,

I wrote a small app that would login on a website, get some statistics and post them back to me.

The login procedure is pretty long (takes 3 pages >> login >> redirect >> accept terms >>), I wanted to make it go more smooth and saw they used cookies for verification. If you have the cookie with nick and pass, it assumes you have it from previous session and creates a new session id.

I just need to set a cookiefile with following cookies:

myNick
myPass
PHPSESSID

I'm guessing I go about that like this:

Code: Select all

$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    $res=curl_exec($ch);
    curl_close($ch);
But how do I define the cookies in the $cookie_file_path file?