PHP code example of antikirra / token

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

    

antikirra / token example snippets




declare(strict_types=1);

use Antikirra\AbstractToken;

ry, you can override the token type
    // protected static function definedType(): int
    // {
    //     // token type in the range from 1 to 255
    //     return 1;
    // }

    // salt definition is a prerequisite for declaring a child class
    protected static function definedSalt(): string
    {
        // random string of arbitrary length
        // !!! DO NOT MODIFY AFTER SETUP !!!
        return '@5dCG!sZP%bF6e38K+xaa~R!2pp2r+b+r=9RXS+aYf?xT2Dc_Pp5@3k775fyH76P';
    }
}

$token = MySecretToken::create(123456, new DateTimeImmutable('+1 day'));

var_dump((string)$token); // AQBA4gEAAAAAAAcBvGXmTCS9BhCtddOfctGTZQLT_Be1EQ

print_r($token);
// MySecretToken Object
// (
//     [type:protected] => 1
//     [identity] => 123456
//     [expiredAt:protected] => DateTimeImmutable Object
// (
//     [date] => 2024-01-01 00:00:00.000000
//             [timezone_type] => 3
//             [timezone] => UTC
//         )
//
//     [nonce:protected] => 4061102716
//     [signature:protected] => <binary>
// )