PHP code example of enlivenapp / flight-csrf

1. Go to this page and download the library: Download enlivenapp/flight-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/ */

    

enlivenapp / flight-csrf example snippets


use Enlivenapp\FlightCsrf\Plugin;

$plugin = new Plugin();
$plugin->register(Flight::app(), Flight::router());

use Enlivenapp\FlightCsrf\Middlewares\CsrfMiddleware;

Flight::route('POST /login', function () {
    // ...
})->addMiddleware(new CsrfMiddleware(Flight::app()));

// Or protect a group
Flight::group('/admin', function () {
    Flight::route('POST /save', function () { /* ... */ });
    Flight::route('DELETE /remove/@id', function ($id) { /* ... */ });
}, [new CsrfMiddleware(Flight::app())]);

// app/config/config.php
return [
    // ...
    'enlivenapp.flight-csrf' => [
        'token_lifetime' => 3600,
        'exclude_routes' => [
            '/webhooks/stripe',
            '/api/public/callback',
        ],
    ],
];
html+php
<form method="POST" action="/login">
    <?= csrf_field()