Saturday, April 18, 2009

PHP : How to use cookie jar with curl

If you want to use cookie jar with your curl code at PHP script, you'll need to use the below few lines with your curl code.

$cookie_file = "/tmp/cookie/cookie1.txt";
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);

These small piece of code chunk will enable you to use the assigned text file as cookie jar. But remember few things. First of all, you have to have use the two lines to set curl options for your cookie jar.

Secondly, please put absolute path with your cookie file name. Otherwise it may not get the cookie file while browsing from browser. Few web server work, but still keep yourself at safe side.

Finally, and must, you have to give your apache user to write access on the cookie file. Otherwise you know, it will get error.

Let me know if I missed anything, or miss guided you. I'm a human too :-)

No comments:

Get function name programaticaly - Python

This little piece of code will help you to get the function name programatically. This is very helpful when you are implementing the debug...