PHP code example of mahdy / wpnonce

1. Go to this page and download the library: Download mahdy/wpnonce 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/ */

    

mahdy / wpnonce example snippets


$nonce =  new \WpNonce\Nonce("Xaction");

$nonce =  new \WpNonce\Nonce();
$nonce->setAction("Xaction");

$nonce->setName("theNewName");

/*if you didn't set the action in constructor, you have to use setter before to use this function*/
$nonce_string = $nonce->generateNonce();

/*use the object directly */
$str = "the following object will return as Nonce string ".$nonce;

$url = "https://somewebsite.com/";
$nonce_url = $nonce->generateNonceUrl($url);

$nonce_HTML_input = $generateNonceField()

if (\WpNonce\NonceVerifier::verify($nonce, $action)) {...}

if (\WpNonce\NonceVerifier::checkAdminReferer($action)) {...}

if (\WpNonce\NonceVerifier::checkAjaxReferer($action)) {...}