PHP code example of ixbox / moonlight

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

    

ixbox / moonlight example snippets


use Ixbox\Moonlight\GiftBox;
use Ixbox\Moonlight\Patisserie;

// Open a shop with the attributes shared across the site
$patisserie = new Patisserie([
    'path' => '/',
    'secure' => true,
    'httponly' => true,
    'samesite' => 'Lax',
]);

$box = new GiftBox();
$box[] = $patisserie->bake('session_id', $sessionId);
$box[] = $patisserie->bake('theme', 'dark', [
    'expires' => time() + 60 * 60 * 24 * 30,
    'httponly' => false, // Override: JavaScript needs to read this one
]);

$response = $box->presentTo($response);
// Set-Cookie: session_id=...; Path=/; Secure; HttpOnly; SameSite=Lax
// Set-Cookie: theme=dark; Expires=...; Max-Age=2592000; Path=/; Secure; SameSite=Lax

use Ixbox\Moonlight\Cookie;

$cookie = (new Cookie('lang', 'en'))
    ->withPath('/')
    ->withExpires(time() + 3600)
    ->withSameSite(Cookie::SAME_SITE_STRICT);

echo $cookie; // lang=en; Expires=...; Max-Age=3600; Path=/; SameSite=Strict

$box[] = $patisserie->bake('session_id')->expire();
// Set-Cookie: session_id=; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-Age=0; Path=/; Secure; HttpOnly; SameSite=Lax

$box = new GiftBox([$cookieA, $cookieB]);
$box->add('name', 'value', ['path' => '/']); // Create a cookie and put it in
$box[] = $cookie;                             // Put a cookie in, keyed by its name
$box['name'];                                 // Get a cookie (null if missing)
unset($box['name']);                          // Remove a cookie
count($box);
foreach ($box as $name => $cookie) { /* ... */ }