Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Generate and store token $_SESSION["csrf"] = bin2hex(random_bytes(32)); // In form echo "<input type=\"hidden\" name=\"csrf\" value=\"{$_SESSION["csrf"]}\">"; // Verify on submit if (!hash_equals($_SESSION["csrf"], $_POST["csrf"] ?? "")) { http_response_code(403); exit("CSRF check failed"); } // Laravel: @csrf in Blade forms — handled automatically
Result
Open