30th June 2011 - 6 minutes read time
I recently needed to create a function that would read and extract cookies from a Netscape HTTP cookie file. This file is generated by PHP when it runs CURL (with the appropriate options enabled) and can be used in subsequent CURL calls. This file can be read to see what cookies where created after CURL has finished running. As an example, this is the sort of file that might be created during a typical CURL call.
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
www.example.com FALSE / FALSE 1338534278 cookiename value
The first few lines are comments and can therefore be ignored. The cookie data consists of the following items (in the order they appear in the file.