PHP code example of niko9911 / react-http-middleware-session
1. Go to this page and download the library: Download niko9911/react-http-middleware-session 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/ */
niko9911 / react-http-middleware-session example snippets
declare(strict_types=1);
// Cache must be persisted. Array cache will not work.
// Just abstract Example. You need to implement
// \React\Cache\CacheInterface::class interface.
use Niko9911\Harold\Core\Http\Application\Middleware\SessionMiddleware;$cache = new \React\Cache\ArrayCache();
// Or
// This is just example here. I personally use PSR
// implementation with bridge and I save all to Redis.
// This will be much easier if using redis other than
// just ReactPHP stuff. You need to Id\Random()
);
new \React\Http\Server(
[
$session,
function (\Psr\Http\Message\ServerRequestInterface $request) {
/** @var \Niko9911\React\Middleware\Session\Session $session */
$session = $request->getAttribute(SessionMiddleware::ATTRIBUTE_NAME);
if (!$session->isActive())
{
$session->begin();
}
echo $session->getId();
return new \React\Http\Response();
}
]
);