Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?
  2.  
  3. public function uniqid()
  4.     {
  5.         $is_not_found_in_db = 0;
  6.  
  7.         while ($is_not_found_in_db==0)
  8.         {
  9.             if (function_exists("random_bytes")) {
  10.                 $bytes = random_bytes(ceil($lenght / 2));
  11.             } elseif (function_exists("openssl_random_pseudo_bytes")) {
  12.                 $bytes = openssl_random_pseudo_bytes(ceil($lenght / 2));
  13.             } else {
  14.                 throw new Exception("Utils.php:uniqid() - no cryptographically secure random function available");
  15.             }
  16.             $uniqueid = substr(bin2hex($bytes), 0, $lenght);
  17.  
  18.             $count = Submission::where('unique_id', $uniqueid)->count();
  19.             if ($count===0)
  20.             {
  21.                 $is_not_found_in_db=1;
  22.             }
  23.         }
  24.         return $uniqueid;
  25.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement