<commit_before><?php

require __DIR__ . '/../vendor/autoload.php';

$csrf = new \Riimu\Kit\CSRF\CSRFHandler();
$csrf->validateRequest();

$token = $csrf->getToken();

if (isset($_POST['myname'])) {
    echo "<p>Hello " . htmlspecialchars($_POST['myname']) . "!</p>";
}
?>

<h1>Form with CSRF token</h1>
<form method="post" action="form.php">
<input type="hidden" name="csrf_token" value="<?=$token?>" />
What is your name?
<input type="text" name="myname" value="" />
<input type="submit" value="Submit" />
</form>

<h1>Form without CSRF token</h1>
<form method="post" action="form.php">
What is your name?
<input type="text" name="myname" value="" />
<input type="submit" value="Submit" />
</form><commit_msg>Update the example<commit_after><?php

require __DIR__ . '/../vendor/autoload.php';
$csrf = new \Riimu\Kit\CSRF\CSRFHandler();

try {
    $csrf->validateRequest(true);
} catch (\Riimu\Kit\CSRF\InvalidCSRFTokenException $ex) {
    header('HTTP/1.0 400 Bad Request');
    exit('Bad CSRF Token!');
}

$token = $csrf->getToken();

?>
<!DOCTYPE html>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Simple Form</title>
 </head>
 <body>
<?php

if (!empty($_POST['my_name'])) {
    printf("  <p>Hello <strong>%s!</strong></p>" . PHP_EOL, htmlspecialchars($_POST['my_name']));
}

?>
  <h3>Form with a CSRF token:</h3>
  <form method="POST" action="<?=htmlspecialchars($_SERVER['PHP_SELF'])?>"><div>
   <input type="hidden" name="csrf_token" value="<?=htmlspecialchars($token)?>" />
   What is your name?
   <input type="text" name="my_name" />
   <input type="submit" />
  </div></form>

  <h3>Form without a CSRF token:</h3>
  <form method="POST" action="<?=htmlspecialchars($_SERVER['PHP_SELF'])?>"><div>
   What is your name?
   <input type="text" name="my_name" />
   <input type="submit" />
  </div></form>
 </body>
</html>
{'fraction_non_alphanumeric': 0.22949946751863684, 'fraction_numerical': 0.007454739084132056, 'mean_word_length': 4.908805031446541, 'pattern_counts': {'":': 0, '<': 56, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7083925', 'n_tokens_mistral': 706, 'n_tokens_neox': 709, 'n_words': 142}