PHP code example of natilosir / cookie

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

    

natilosir / cookie example snippets


use natilosir\cookie\Cookie;

// Set a cookie
Cookie::set('username', 'JohnDoe', 7); // Expires in 7 days

// Get the cookie value
$username = Cookie::get('username');
echo 'Username: ' . $username; // Outputs: Username: JohnDoe

// Delete the cookie
Cookie::delete('username');

// List all cookies
$allCookies = Cookie::list();
print_r($allCookies); // Outputs all cookies

use natilosir\cookie\Cookie;

// Set a cookie
Cookie::set('username', 'JohnDoe', 7);

// Get the cookie value
$username = Cookie::get('username');
echo 'Username: ' . $username; // Outputs: Username: JohnDoe

// Delete the cookie
Cookie::delete('username');

// List all cookies
$allCookies = Cookie::list();
print_r($allCookies); // Outputs all cookies