PHP code example of kegi / netscape-cookie-file-handler

1. Go to this page and download the library: Download kegi/netscape-cookie-file-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kegi / netscape-cookie-file-handler example snippets


/*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();