PHP code example of initphp / cookies

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

    

initphp / cookies example snippets


$options = [
        'ttl'       => 2592000, // 30 days
        'path'      => '/',
        'domain'    => null,
        'secure'    => false,
        'httponly'  => true,
        'samesite'  => 'Strict'
];


use InitPHP\Cookies\Cookie;

$cookie = new Cookie('cookie_name', 's£cr£t_s@lt', []);
$cookie->set('username', 'sdd');

public function has(string $key): bool;

public function get(string $key, $default = null): mixed;

public function pull(string $key, $default = null): mixed;

public function set(string $key, string|bool|int|float $value, ?int $ttl = null): self;

public function setArray(string[] $assoc, ?int $ttl = null): self;

public function remove(string ...$key): bool;

public function push(set $key, string|bool|int|float $value, ?int $ttl = null): string|bool|int|float;

public function all(): array;

public function flush(): bool;

public function destroy(): bool;