File src/class/Utility/CSRF.php
class Lia\Utility\CSRF
Print and validate CSRF tokens for forms.
See source code at /src/class/Utility/CSRF.php
Constants
Properties
-
static protected array $valid_requests = [];Array of form_id:token pairs that have been successfully validated during this request. -
static protected array $generated_csrf = [];Array of csrf entries that have been generated during this request. There can only be one for each form id.
Methods
-
static public function get_csrf_input(string $form_id, string $uri_path = '', int $expiry_minutes 60): stringGet a form input to use for CSRF protection. Print this in your form. Both the input's name and value are randomly generated.
The SESSION will be set with the CSRF Key/Value pair for the given form_id -
static public function is_request_valid(string $form_id, array $form_data): boolCheck if a valid CSRF Key/Value pair is present within form_data for the given form_id -
static public function get_csrf_value(string $form_id, string $uri_path = '', int $expiry_minutes 60): stringGenerate a CSRF entry for the given form_id and return the CSRF value. There can only be one CSRF token generated for each form id, and if it has already been generated, it will be returned. -
static public function get_csrf_key(string $form_id) -
static protected function make_csrf_code(): stringGenerate a random CSRF value (used both as key and value)