Cookie Handling

Posted by m6w6 on 22nd May 2006 in Mike's sudden inspirations: PHP

I noticed some weirdance about how libcurl and thus pecl/http handles cookies.

I had to implement some changes which are only in CVS for now and which Iā€™m going to outline here:

$r = new HttpRequest("");  
$r->recordHistory = true;  
// we don't care about cookies by default  
// enable automatic recognition of cookies  
// received cookies will be sent on the next request  
// reset those "auto" cookies  
// this needs at least libcurl >= v7.14.1  
echo $r->getHistory()->toString(true);  

Beware that all this does not affect custom cookies set with HttpRequest::setCookies() and HttpRequest::addCookies(). Custom cookies can always be unset by calling HttpRequest::setCookies().

A final note on using the cookiestore option:

$r = new HttpRequest("");  
// load and save cookies from /tmp/cookies.txt  
// if 'cookiesession' is TRUE, session cookies  
// won't be loaded from the cookiestore  
    "cookiesession" => TRUE,  
    "cookiestore" => "/tmp/cookies.txt")  

Note that using the cookiestore automatically enables libcurls cookie engine.