This library allows you to manipulate Netscape Cookie File (eg. Cookies generated by CURL).
This is library is only available for PHP7+ There is no other dependencies
This library is available on packagist (Composer)
composer require kegi/netscape-cookie-file-handler
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.
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();
Learn how to use the library here : documentation.
Feel free to contact me or send pull requests !