PHP code example of drewlabs / http-cookie

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

    

drewlabs / http-cookie example snippets



use Drewlabs\Cookies\Factory;

$factory = new Factory;

$cookie = $factory->create('sessionid', random_int(10000, 100000) . time()); // CookieInterface

// API

$cookie->getName(); // sessionid -> Returns the cookie name

$cookie->getValue(); // -> Returns cookie value

$cookie->isHttpOnly(); // Check if the cookie is http only

$cookie->isSecure(); // Check if the cookie is secure

// etc...


use Drewlabs\Cookies\FactoryProxy as Factory;

$cookie = Factory::create('sessionid', random_int(10000, 100000) . time()); // CookieInterface



use Drewlabs\Cookies\FactoryProxy as Factory;

$cookie = Factory::create('sessionid', random_int(10000, 100000) . time()); // CookieInterface

printf("%s\n", (string)$cookie); // sessionid=428461690891271; Path=/; Secure; HttpOnly; SameSite=Lax