PHP code example of guilherme / konf-cookie

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

    

guilherme / konf-cookie example snippets


use Guilherme\KonfCookie\Cookie;

$cookie = new Cookie();

// Set a cookie that expires in 1 hour
$cookie->set('user', 'john_doe', 3600);

$cookie->set(
    'user',      // Cookie name
    'john_doe',  // Cookie value
    3600,        // Expiration in seconds
    '/',         // Path
    '',          // Domain
    true,        // Secure (HTTPS only)
    true         // HttpOnly (not accessible by JavaScript)
);

$user = $cookie->get('user');
echo $user; // Outputs: john_doe

if ($cookie->exists('user')) {
    echo "Cookie 'user' exists!";
} else {
    echo "Cookie 'user' does not exist!";
}

$cookie->destroy('user'); // Simple deletion

// Deleting with custom options
$cookie->destroy('user', '/', '', true, true);

$allCookies = $cookie->getAll();
print_r($allCookies);

use Guilherme\KonfCookie\Cookie;

$cookie = new Cookie();

// Set a cookie
$cookie->set('user', 'john_doe', 3600);

// Get a cookie
echo $cookie->get('user');

// Check if it exists
if ($cookie->exists('user')) {
    echo "Exists!";
}

// List all cookies
print_r($cookie->getAll());

// Delete it
$cookie->destroy('user');