<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wyrihaximus / react-http-middleware-session example snippets
$server = new Server(
$loop,
/** Other Middleware */
new SessionMiddleware(
'CookieName',
$cache, // Instance implementing React\Cache\CacheInterface
[ // Optional array with cookie settings, order matters
0, // expiresAt, int, default
'', // path, string, default
'', // domain, string, default
false, // secure, bool, default
false // httpOnly, bool, default
],
),
/** Other Middleware */
function (ServerRequestInterface $request) {
$session = $request->getAttribute(SessionMiddleware::ATTRIBUTE_NAME);
// Overwrite session contents, the details of changing specific keys is up to you
$session->setContents([
'foo' => 'bar',
]);
// Get session contents
var_export($session->getContents()); // Prints something like: ['foo' = 'bar']
return new Response();
}
);
$array = $session->toArray();
// Transfer to child process
$session = (new Session('', [], new RandomBytes()))->fromArray($array);
// The same can be done transferring changes back to the parent
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.