1. Go to this page and download the library: Download chiron/csrf 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/ */
chiron / csrf example snippets
[
//...
XXX\CsrfBootloader::class,
]
use Chiron\Csrf\Middleware\CsrfProtectionMiddleware;
// ...
public function boot(RouterInterface $router)
{
$route = new Route('/', new Target\Action(HomeController::class, 'index'));
$router->setRoute(
'index',
$route->withMiddleware(CsrfProtectionMiddleware::class)
);
}
use Chiron\Csrf\Middleware\CsrfProtectionMiddleware;
// ...
public function boot(MiddlewareQueue $middlewares)
{
$middlewares->addMiddleware(CsrfProtectionMiddleware::class);
}
public function index(ServerRequestInterface $request)
{
$csrfToken = $request->getAttribute('csrfToken');
}