PHP code example of enjoys / cookie

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

    

enjoys / cookie example snippets


use Enjoys\Cookie\Options;

/** @var \Psr\Http\Message\ServerRequestInterface $request */
$cookieOptions = new Options($request);
$cookieOptions->setDomain('example.com'); //default: false (localhost)
$cookieOptions->setPath('/'); //default: '' (string empty)
$cookieOptions->setSecure(true); //default: false
$cookieOptions->setHttponly(true); //default: false
$cookieOptions->setSameSite('Strict'); //default: Lax

use Enjoys\Cookie\Cookie;
use Enjoys\Cookie\Options;

/** @var Options $cookieOptions */
$cookie = new Cookie($cookieOptions);

$cookie->set('key', 'value<>', $ttl = true, $options = []);
$cookie->setRaw('key', 'value<>');
$cookie->delete('key');
$cookie->get('key');
$cookie->has('key');