Download the PHP package picios/tokenizer without Composer
On this page you can find all versions of the php package picios/tokenizer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package tokenizer
Tokenizer
This library helps to create and validate url valid tokens and store some data within it. Such token can not be changed, otherwise it's not valid anymore.
Installation
Install with composer
Usage
Creating a new token
You need to create the token first, to e.g. send it as a query parameter in en email message
Parsing the token
Incoming token must be validated by the TokenManager::parse() function
Creation time
You can easily check the token creation time to consider its expiration
How it works
The token allows you to store a limited amount of data in one string in a safe way.
To create a new token, you need to get TokenManager object with parameters SEED and a structure of the data in token. It's a simple array with names of the token data fields. The SEED and the structure must be the same during creating the token and when you parse it.
When the TokenManager object is set, you may call its createToken(array data) function, of which the only required parameter is the associeted array with the data, you want to store in the token. The data array must contain exactly the same fields, as in the structure from the TokenManager object.
The data in the token are explicit, just encoded with base64 algorythm. They can be easly decoded. For the above example token
a decoded string is
First 6 characters is a substring of a md5 hash created from all the data in the token plus the secret seed known only on the server side. The next 25 characters is a date of creating the token in ATOM format. The rest is the data encoded with the JSON format.
It's safety and unchangeability comes from the simple hash, that is a kind of a checksum of our token.
Troubleshooting
- you need to remember that all the data in the token are easily decodable, so don't place any confidential data in it.
- the capacity of the token is limited to the purpose, you use it for. For example if you put it as a part of a URL query, according to the HTTP spec, there is no limit to a URL's length, but keep your URLs under 2048 characters so it would work well with IE browser.
Testing
To test the class, run:
Homepage
You can read more at Picios.pl