Skip to content

gbrousse/php-token-manager

Repository files navigation

php-token-manager Build Status Coverage Status

Total Downloads Latest Stable Version

Secure your web ressources (files, images, streams, ...) with simple token system.

Installation

Install the latest version with

$ composer require gbrousse/php-token-manager

Basic usage

get a token

<?php

use TokenManager\TokenManager; 

// Setup
$options = array(
    'dir' => 'directory/where/stock/tokens',
    'prefix' => 'prefix_of_tokens_files',
    'salt' => 'salt',
    'hash' => 'md5', // hash use to generate token
    'maxTimeout' => 7200, //max lifetime for a token
    'maxTimeout' => 600, //min lifetime for a token
); 
$TokenMgr = new TokenManager($options);
     
// Get token
$token = $TokenMgr->get();

If you use a single configuration for the tokens, modify the attributes of the class instead of using options array.

Verify a token

<?php

use TokenManager\TokenManager; 


// Setup
$options = array(
    'dir' => 'directory/where/stock/tokens',
    'prefix' => 'prefix_of_tokens_files',
    'salt' => 'salt',
    'hash' => 'md5', // hash use to generate token
    'maxTimeout' => 7200, //max lifetime for a token
    'maxTimeout' => 600, //min lifetime for a token
); 
$TokenMgr = new TokenManager($options);
     
// Verify token validity
if($TokenMgr->isValid($token)){
    // action to do if token is OK
} 

If you use a single configuration for the tokens, modify the attributes of the class instead of using options array.

Examples

About

Requirements

  • php-token-manager works with PHP 5.3 or above.

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub

Author

Gregory Brousse - pro@gregory-brousse.fr - http://gregory-brousse.fr

License

php-token-manager is licensed under the LGPL-3.0 License - see the LICENSE file for details

About

Secure your web ressources (files, images, streams, ...) with tokens

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages