kegi/netscape-cookie-file-handler

Netscape Cookie File Handler

1.0.3 2016-02-20 00:20 UTC

This package is not auto-updated.

Last update: 2024-11-09 19:45:39 UTC


README

Build Status Latest Stable Version Test Coverage

Issue Count Code Climate SensioLabsInsight

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 !