Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- public function uniqid()
- {
- $is_not_found_in_db = 0;
- while ($is_not_found_in_db==0)
- {
- if (function_exists("random_bytes")) {
- $bytes = random_bytes(ceil($lenght / 2));
- } elseif (function_exists("openssl_random_pseudo_bytes")) {
- $bytes = openssl_random_pseudo_bytes(ceil($lenght / 2));
- } else {
- throw new Exception("Utils.php:uniqid() - no cryptographically secure random function available");
- }
- $uniqueid = substr(bin2hex($bytes), 0, $lenght);
- $count = Submission::where('unique_id', $uniqueid)->count();
- if ($count===0)
- {
- $is_not_found_in_db=1;
- }
- }
- return $uniqueid;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement