netscape-cookie-file-handler
netscape-cookie-file-handler copied to clipboard
Handler for netscape cookie file (eg. Cookies saved by CURL)
Netscape Cookie File Handler
This library allows you to manipulate Netscape Cookie File (eg. Cookies generated by CURL).
Requirements
This is library is only available for PHP7+ There is no other dependencies
Installation
This library is available on packagist (Composer)
composer require kegi/netscape-cookie-file-handler
What are Cookies Files ?
The Netscape cookie files are widely used. Curl, by example, allows you to select a file (called the cookie jar) to save and read the cookies using this format. This library will help you to manipulate and read those cookies.
Example
Simple example of reading + writing cookies
/*Open and parse the cookie file*/
$configuration = (new Configuration())->setCookieDir('cookies/');
$cookieJar = (new CookieFileHandler($configuration))->parseFile('my_cookie_file');
/*Add (and save) a cookie*/
$cookieJar->add(
(new Cookie())
->setHttpOnly(true)
->setPath('/foo')
->setSecure(true)
->setExpire(new DateTime('2020-02-20 20:20:02'))
->setName('foo')
->setValue('bar')
)->persist();
Documentation
Learn how to use the library here : documentation.
Contribution
Feel free to contact me or send pull requests !