Is there a certain size uniqid function?

I'm just wondering, does anyone know if a uniqid function in PHP has a specific size? And if so, how many lines? I'm a bit confused as the PHP manual says that uniqid is 23 characters long when using extended entropy. But, based on my observation, it varies from 26 to 28 characters.

+4
source share
1 answer

I can not confirm this behavior:

php -r 'for($i = 0; $i < 1000; $i++) print strlen(uniqid("", true)) . "\n";' 

Tested on OS X and Ubuntu with PHP 5.3.x gives 23 on each iteration.

What version of os / PHP are you using?


As the OP pointed out in the comments on his question: prefix exclusion should fix the problem;)

To develop a little more, you can look at the PHP source code: https://svn.php.net/viewvc/php/php-src/tags/php_5_3_8/ext/standard/uniqid.c?view=markup on line 79:

 spprintf(&uniqid, 0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10); 

If no prefix is ​​given and one searches for a php_combined_lcg definition that returns a float with one leading decimal number, the uniqid output should always contain 23 characters.

+2
source

All Articles