PHP code example of rnr1721 / le7-cookie-wrapper

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

    

rnr1721 / le7-cookie-wrapper example snippets


use Core\Cookies\CookiesConfigDefault;
use Core\Cookies\CookiesNative;

    // This is the default config
    $newConfig = [
        'domain' => '',
        'httpOnly' => false,
        'path' => '',
        'isSecure' => false,
        'time' => 0,
        'sameSite' => 'Lax',
    ];

    // Implementation of Core\Interfaces\CookieConfigInterface
    $config = new CookiesConfigDefault($newConfig);

    // Second case to add params
    // $config->setParams($newConfig);

    // Implementation of Core\Interfaces\CookieInterface
    $cookies = new CookiesNative($config);

    // Before operations with cookies you can set more concrete params
    // These params will override defaults
    // $cookies->setPath('/');
    // $cookies->setHttpOnly(true);
    // $cookies->setSameSite('Lax');
    // $cookies->setSecure(true);
    // $cookies->setTime(3600);

    $cookies->get('mycookie'); //return cookie value by key;
    $cookies->get('mycookie','default'); //return cookie value by key or default;
    $cookies->has('mycookie'); // return bool if cookie exists or not
    $cookies->delete('mycookie'); // delete cookie 


use Core\Session\SessionNative;

    $session = new Core\Session\SessionNative();

    // start the session
    $session->start();

    // Set param one with value test1
    $session->set('one', 'test1');

    // get param one or null if not exists
    $session->get('one');

    // get param one or default value if not exists
    $session->get('one','default value');

    // Return bool if param exists or not
    $session->has('one');

    // Delete the param
    $session->delete('one');

    // Return bool if session started or not
    $session->isStarted();

    // Clear session
    $session->clear()

    // Destroy the session
    $session->destroy();