Cookies in php (curl)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gabiru
Forum Newbie
Posts: 1
Joined: Wed May 28, 2008 8:58 am

Cookies in php (curl)

Post 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?
Post Reply