PHP code example of izzle / token-handler

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

    

izzle / token-handler example snippets


use Izzle\TokenHandler\Model\Token;
use Illuminate\Encryption\Encrypter;
use Izzle\TokenHandler\Handler\FileHandler;

// Owner Id for this token. Must be unique. Ex. a User Id.
$ownerId = 'someOwnerId';

// Encrypter with random 16 Key for Cipher AES-128-CBC
// Cipher AES-256-CBC will need a 32 Char Key
$encrypter = new Encrypter('01234567890123456');

$token = (new Token())->setToken('someToken')
    ->setExpires(time() + 3600) // Ex. expires in 60 Minutes
    ->setOwnerId($ownerId);

$tokenHandler = new FileHandler(sys_get_temp_dir(), $encrypter);
$tokenHandler->saveToken($token, $ownerId);

use Illuminate\Encryption\Encrypter;
use Izzle\TokenHandler\Handler\FileHandler;

// Owner Id for this token. Must be unique. Ex. a User Id.
$ownerId = 'someOwnerId';

// Encrypter with random 16 Key for Cipher AES-128-CBC
// Cipher AES-256-CBC will need a 32 Char Key
$encrypter = new Encrypter('01234567890123456');

$tokenHandler = new FileHandler(sys_get_temp_dir(), $encrypter);
$token = $tokenHandler->loadToken($ownerId);