1. Go to this page and download the library: Download elhardoum/nonce-php 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/ */
elhardoum / nonce-php example snippets
// nonce configuration class
$nonceConfig = new \Nonce\Config\Config;
// nonce hash storage, use browser cookies
$nonceStore = new \Nonce\HashStore\Cookie;
// initialize nonce class
$nonceUtil = new \Nonce\Nonce( $nonceConfig, $nonceStore );
// make sure you make this call before starting the output or sending HTTP headers
$nonce = $nonceUtil->create( 'signup-form' );
if ( isset( $_POST['nonce'] ) && $nonceUtil->verify( $_POST['nonce'], 'signup-form' ) ) {
# nonce is valid
}
// nonce configuration class
$nonceConfig = new \Nonce\Config\Config;
// initialize nonce class
$nonceUtil = new \Nonce\Nonce( $nonceConfig, new \Nonce\HashStore\Cookie );
$nonceUtil = new \Nonce\Nonce( $nonceConfig, new \Nonce\HashStore\Cookie );
// initialize the class passing an instance of Predis as the first argument
$nonceStore = new \Nonce\HashStore\Redis( new \Predis\Client() );
$nonceUtil = new \Nonce\Nonce( $nonceConfig, $nonceStore );
class CustomStore implements \Nonce\HashStore\Store
{
/**
* Store a key temporarily
*
* @param string $name key to be stored
* @param string $value value to be stored for the given key
* @param int $expire_seconds expire the data after X seconds (data TTL)
* @return bool success/failure
*/
public function setKey( string $name, string $value, int $expire_seconds=0 ) : bool
{
// ...
}
/**
* Get a key from temporary storage
*
* @param string $name key to be retrieved
* @return string value for stored key or empty string on key unavailable
*/
public function getKey( string $name ) : string
{
// ...
}
/**
* Unset a key from temporary storage
*
* @param string $name key to be removed
* @return bool success/failure
*/
public function deleteKey( string $name ) : bool
{
// ...
}
}