1. Go to this page and download the library: Download pedroac/nonce 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/ */
pedroac / nonce example snippets
Symfony\Component\Cache\Simple\FilesystemCache;
use \pedroac\nonce\NoncesManager;
use \pedroac\nonce\Form\HtmlNonceField;
use \pedroac\nonce\Form\NonceForm;
// this handles automatically the input and nonce management
$form = new NonceForm(
'token', // the HTML input name
new NoncesManager(
new FilesystemCache // a \Psr\SimpleCache\CacheInterface implementation
)
);
// this will be used to generate a HTML input element
$htmlField = new HtmlNonceField($form);
if ($form->isSubmittedValid()) {
/**
* handle the success:
* - if all form input is valid, show success page;
* - otherwise, show an error page and the form again;
*/
}
if ($form->isSubmittedInvalid()) {
/**
* handle failure:
* - don't show the form again;
* - show an error message;
*/
}
<form method="POST">
<?= $htmlField
Symfony\Component\Cache\Simple\FilesystemCache;
use \pedroac\nonce\NoncesManager;
$manager = new NoncesManager(new FilesystemCache);
Symfony\Component\Cache\Simple\ArrayCache;
use \pedroac\nonce\NoncesManager;
use \pedroac\nonce\Random\HexRandomizer;
$manager = new NoncesManager(
new ArrayCache(60),
new HexRandomizer(32), // a \pedroac\nonce\Random implementation
new \DateInterval('PT3H')
);