#69: Using Cookies

If your application requires that you log in to a server that has cookie-based authentication, then you need to enable a cookie collection system in cURL. The idea is that when you access a page, cURL stores the cookies it receives in a file (called the cookie jar), and upon subsequent accesses, you want cURL to check that file for any cookies that it should send to the server.

Typically, you need to add two configuration lines: the first to set the write location and the second to set the read location:

curl_setopt(c, CURLOPT_COOKIEJAR, 'cookiejar');
curl_setopt(c, CURLOPT_COOKIEFILE, 'cookiejar');

Here, c is a cURL connection handle, and cookiejar is a PHP-writable file.

The biggest problem with this scheme is that it does not ...

Get Wicked Cool PHP now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.