PHP code example of popphp / pop-cookie

1. Go to this page and download the library: Download popphp/pop-cookie 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/ */

    

popphp / pop-cookie example snippets


use Pop\Cookie\Cookie;

$cookie = Cookie::getInstance([
    'path'   => '/',
    'expire' => time() + 3600,
]);

$options = [
    'path'     => '/',
    'expire'   => time() + 3600,
    'domain'   => 'www.domain.com',
    'secure'   => true,
    'httponly' => true,
    'samesite' => 'Lax'  // 'Lax', 'Strict', 'None'
];

// Set cookie values
$cookie->foo = 'bar';
$cookie['baz'] = 123;

echo $cookie->foo;
echo $cookie['baz'];

unset($cookie->foo);
unset($cookie['baz']);