Creates unique static ID.
- PHP >=
5.5
Composer (Recommended)
Run the command the following from within your project directory:
composer require sak32009/unique-id
include "vendor/autoload.php";
If you want to install manually, on the main page you can download or clone the repo.
include "src/sak32009/unique-id.php";
$uniqueID = new sak32009\uniqueID;
$uniqueID->setOption('hash_salt', 'my_private_key');
$cookie = $_COOKIE['cookie'];
if(strlen($cookie) > 0){
if($uniqueID->verify($cookie)){
echo "OK! Hash: " . $cookie;
}else{
echo "Hash invalid";
}
}else{
$hash = $uniqueID->generateID();
setcookie('cookie', $hash, (time()+60*60*24*30));
echo "Reload page";
}
For generate ID use $uniqueID->generateID()
:
$uniqueID->generateID();
For verify hash use $uniqueID->verify(hash)
:
$uniqueID->verify('$2y$10$pBxDPcYxwy9C/NAhgCuoHun5YeTqY/1CTZBT71R4cY3L8xFys2Q5G');
Note: Use this to check if hash corresponds to the user.
For set options use $uniqueID->setOption(key, val)
:
$uniqueID->setOption('hash_salt', 'my_private_key');
Note: See options
section.
For add more data use $uniqueID->addData(str)
:
$uniqueID->addData($_SERVER['SCRIPT_NAME']);
Note: This makes the ID much safer.
hash_salt Default: null, Type: string
See this link WIKIPEDIA, in short is the private key.
$uniqueID->setOption('hash_salt', 'my_private_key');
This software is distributed under the MIT license. Please read LICENSE for information on the software availability and distribution.
See the releases pages for a history of releases and highlights for each release.
Maintained under the Semantic Versioning guidelines as much as possible. Releases will be numbered with the following format:
<major>.<minor>.<patch>
For more information, please visit SEMVER.
- Sak32009
<https://github.com/Sak32009>