Skip to content

Instantly share code, notes, and snippets.

@Gkiokan
Created January 3, 2017 08:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gkiokan/ca92013913889366c33b5b5847daf948 to your computer and use it in GitHub Desktop.
Save Gkiokan/ca92013913889366c33b5b5847daf948 to your computer and use it in GitHub Desktop.
PHP Token generator
<?php
/*
Gist: PHP Token Generator
Author: Gkiokan Sali
Description: Generate a unique token with a special format.
*/
namespace Gkiokan\Tools;
class Token {
// Generates the Unique Token and returns it.
public static function generate(){
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
mt_rand( 0, 0xffff ),
mt_rand( 0, 0x0C2f ) | 0x4000,
mt_rand( 0, 0x3fff ) | 0x8000,
mt_rand( 0, 0x2Aff ), mt_rand( 0, 0xffD3 ), mt_rand( 0, 0xff4B )
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment