PHP code example of arraypress / wp-signed-tokens

1. Go to this page and download the library: Download arraypress/wp-signed-tokens 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/ */

    

arraypress / wp-signed-tokens example snippets


use ArrayPress\SignedTokens\Secret;

$signer = Secret::signer();

// A download link good for an hour.
$token = $signer->sign( 'download', [ 'file_id' => 42, 'order' => 1001 ], HOUR_IN_SECONDS );
$url   = add_query_arg( 'token', $token, home_url( '/download/' ) );

// On the way back in.
$verified = $signer->verify( 'download', $_GET['token'] ?? '' );

if ( ! $verified ) {
    wp_die( 'This link has expired.' );
}

$file_id = $verified->int( 'file_id' );