PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Aleksandar Zivanovic  >  PHP Secure Token Generator  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Secure Token Generator
Create and validate tokens stored in MySQL table
Author: By
Last change: Changed config for DB connection
Date: 5 years ago
Size: 1,354 bytes


Class file image Download
 * User: Aleksandar Zivanovic <>

/** Load required class */
require_once __DIR__ . '/iToken.php';

$dbHost = 'db_host';

$dbUser = 'db_user';

$dbPass = 'db_pass';

$dbName = 'db_name';

$dbPort = 3306;

// Connect to database ($dbPort is not required, if not set default value is used, default value of port is 3306)
iToken::establishDatabaseConnection($dbHost, $dbUser, $dbPass, $dbName, $dbPort);

// Create itokens table if it doesn't exists

// Get iToken instance
$iToken = new iToken();

// Generate normal token
$token = $iToken->generate();

"Token created: {$token}\n";

"Token {$token} is valid {$iToken->isValid($token)}\n";

// Check is token is valid
if ($iToken->isValid($token)) {

// Remove token

"Token {$token} removed.\n";


// Generate entity token
$entityToken = $iToken->generate('EntityID');

"Entity Token created: {$entityToken}\n";

"Entity Token {$entityToken} is valid {$iToken->isValid($entityToken, 'EntityID')}\n";

// Check is entity token valid
if ($iToken->isValid($entityToken, 'EntityID')) {

// Remove all tokens for given entity

"Entity Tokens removed.\n";


For more information send a message to info at phpclasses dot org.