Skip to content

causefx/unique-id

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

unique-id

Latest Stable Version Total Downloads Latest Unstable Version License Codacy Badge

Description

Creates unique static ID.

Requirements

  • PHP >= 5.5

Installation

Composer (Recommended)

Run the command the following from within your project directory:

composer require sak32009/unique-id
include "vendor/autoload.php";

Direct download

If you want to install manually, on the main page you can download or clone the repo.

include "src/sak32009/unique-id.php";

Usage

$uniqueID = new sak32009\uniqueID;
$uniqueID->setOption('hash_salt', 'my_private_key');

Example

$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():

$uniqueID->generateID();

Verify hash

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.

Set options

For set options use $uniqueID->setOption(key, val):

$uniqueID->setOption('hash_salt', 'my_private_key');

Note: See options section.

Add data

For add more data use $uniqueID->addData(str):

$uniqueID->addData($_SERVER['SCRIPT_NAME']);

Note: This makes the ID much safer.

Options

hash_salt Default: null, Type: string

See this link WIKIPEDIA, in short is the private key.

$uniqueID->setOption('hash_salt', 'my_private_key');

License

This software is distributed under the MIT license. Please read LICENSE for information on the software availability and distribution.

Changelog

See the releases pages 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:

<major>.<minor>.<patch>

For more information, please visit SEMVER.

Author

  • Sak32009 <https://github.com/Sak32009>

About

Creates unique static ID

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages