gbrousse/php-token-manager

PHP library used to secure web ressources (files, images, streams, ...) with simple token system.

v1.0.1-rc 2015-11-04 15:01 UTC

This package is not auto-updated.

Last update: 2024-12-21 19:58:07 UTC


README

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