https://github.com/causefx/unique-id
Creates unique static ID
https://github.com/causefx/unique-id
Last synced: 9 months ago
JSON representation
Creates unique static ID
- Host: GitHub
- URL: https://github.com/causefx/unique-id
- Owner: causefx
- License: mit
- Created: 2017-09-14T21:04:48.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-03T19:51:42.000Z (over 10 years ago)
- Last Synced: 2025-03-25T18:52:33.940Z (over 1 year ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## unique-id
[](https://packagist.org/packages/sak32009/unique-id)
[](https://packagist.org/packages/sak32009/unique-id)
[](https://packagist.org/packages/sak32009/unique-id)
[](https://packagist.org/packages/sak32009/unique-id)
[](https://www.codacy.com/app/Sak32009/unique-id)
## Description
Creates unique static ID.
## Requirements
* PHP >= `5.5`
## Installation
### [Composer](https://getcomposer.org/) (Recommended)
Run the command the following from within your project directory:
```
composer require sak32009/unique-id
```
```php
include "vendor/autoload.php";
```
### Direct download
If you want to install manually, on the main page you can download or clone the repo.
```php
include "src/sak32009/unique-id.php";
```
## Usage
```php
$uniqueID = new sak32009\uniqueID;
$uniqueID->setOption('hash_salt', 'my_private_key');
```
## Example
```php
$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";
}
```
## Functions
### Generate ID
For generate ID use `$uniqueID->generateID()`:
```php
$uniqueID->generateID();
```
### Verify hash
For verify hash use `$uniqueID->verify(hash)`:
```php
$uniqueID->verify('$2y$10$pBxDPcYxwy9C/NAhgCuoHun5YeTqY/1CTZBT71R4cY3L8xFys2Q5G');
```
**Note**: Use this to check if hash corresponds to the user.
### Set options
For set options use `$uniqueID->setOption(key, val)`:
```php
$uniqueID->setOption('hash_salt', 'my_private_key');
```
**Note**: See `options` section.
### Add data
For add more data use `$uniqueID->addData(str)`:
```php
$uniqueID->addData($_SERVER['SCRIPT_NAME']);
```
**Note**: This makes the ID much safer.
## Options
**hash_salt** Default: *null*, Type: string
See this link [WIKIPEDIA](https://en.wikipedia.org/wiki/Salt_%28cryptography%29), in short is the private key.
```php
$uniqueID->setOption('hash_salt', 'my_private_key');
```
## License
This software is distributed under the [MIT](https://opensource.org/licenses/MIT) license. Please read [LICENSE](LICENSE) for information on the software availability and distribution.
## Changelog
See the [releases pages](https://github.com/Sak32009/unique-id/releases) for a history of releases and highlights for each release.
## Versioning
Maintained under the Semantic Versioning guidelines as much as possible. Releases will be numbered with the following format:
`..`
For more information, please visit [SEMVER](http://semver.org).
## Author
* Sak32009 ``