1. Go to this page and download the library: Download pollen-solutions/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/ */
use Laminas\Diactoros\Response;
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
/** @var \Pollen\Cookie\CookieJarInterface $cookieJar */
$cookie = $cookieJar->make('cookie.test', ['value' => 'test']);
$response = new Response();
$response = $response->withAddedHeader('Set-Cookie', (string)$cookie);
(new SapiEmitter())->emit($response);
exit;
use Pollen\Http\Response as HttpResponse;
/** @var \Pollen\Cookie\CookieJarInterface $cookieJar */
$cookie = $cookieJar->make('cookie.test', ['value' => 'test']);
$httpResponse = new HttpResponse();
$httpResponse->headers->setCookie($cookie);
$httpResponse->send();
use Pollen\Cookie\CookieInterface;
use Pollen\Http\Request as HttpRequest;
// In this example, we consider :
// - Global $cookieJar as an implemented instance of CookieJar.
// - An HTTP Response was already sent with cookie1 and cookie2. @see "Send Cookie" above.
/** @var \Pollen\Cookie\CookieJarInterface $cookieJar */
$cookie1 = $cookieJar->get('cookie1');
$cookie1 = $cookieJar->get('cookie2');
$httpValue1 = $cookie1->httpValue();
$httpValue2 = $cookie2->httpValue(HttpRequest::createFromGlobals());
var_dump($httpValue1, $httpValue2);
use Pollen\Http\Request as HttpRequest;
// In this example, we consider :
// - Global $cookieJar as an implemented instance of CookieJar.
// - An HTTP Response was already sent with cookie.test with the value 'test'. @see "Send Cookie" above.
/** @var \Pollen\Cookie\CookieJarInterface $cookieJar */
$cookie = $cookieJar->make('cookie.test', ['value' => 'test']);
var_dump($cookie->checkRequestValue());
use Pollen\Cookie\CookieJar;
use Pollen\Cookie\Middleware\QueuedCookiesMiddleware;
use Pollen\Http\Request;
use Pollen\Http\Response;
use Pollen\Http\ResponseInterface;
use Pollen\Routing\Router;
// Create the Request object
$request = Request::createFromGlobals();
// CookieJar instantiation
$cookieJar = (new CookieJar())->setDefaults($request->getBasePath());
// CookieJar hydratation
$cookie = $cookieJar->make('cookie.test', ['value' => 'test2'])->queue();
// Router instantiation
$router = new Router();
// Setting QueuedCookiesMiddleware
$router->middleware(new QueuedCookiesMiddleware($cookieJar));
// Map a route
$router->map('GET', '/', function (): ResponseInterface {
return new Response('<h1>Hello, World!</h1>');
});
// Catch HTTP Response
$response = $router->handleRequest($request);
// Send the response to the browser
$router->sendResponse($response);
// Trigger the terminate event
$router->terminateEvent($request, $response);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.