1. Go to this page and download the library: Download chubbyphp/chubbyphp-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/ */
chubbyphp / chubbyphp-csrf example snippets
use Chubbyphp\Csrf\CsrfErrorHandlerInterface;
use Chubbyphp\Csrf\CsrfErrorResponseMiddleware;
use Chubbyphp\Csrf\CsrfTokenGenerator;
use Chubbyphp\Session\Session;
$session = new Session();
$middleware = new CsrfErrorResponseMiddleware(
new CsrfTokenGenerator(),
$session,
new class() implements CsrfErrorHandlerInterface {
public function errorResponse(
Request $request,
Response $response,
int $code,
string $reasonPhrase
): Response {
return $response->withStatus($code, $reasonPhrase);
}
}
);
/** @var Slim\App $app */
$app->add($middleware);
use Chubbyphp\Csrf\CsrfMiddleware;
use Chubbyphp\Csrf\CsrfTokenGenerator;
use Chubbyphp\Session\Session;
$session = new Session();
$middleware = new CsrfMiddleware(new CsrfTokenGenerator(), $session);
/** @var Slim\App $app */
$app->add($middleware);