Welcome Guest, Not a member yet? Register   Sign In
Unique ID for user directory ?
#1

[eluser]mci[/eluser]
Hi

I need a unique ID for user directories. Will
Code:
md5(uniqid());
be the right one for this or do you suggest another solution? I'm thinking about to us this unique ID also for the user activation link.
#2

[eluser]WanWizard[/eluser]
Try to avoid uniqueid(), it's not very portable. It also generates id's which are hex values of the current time, not necessarily that unique.

Instead, I would go for UUID's. There's a PECL extension for it, and there are also native PHP versions floating around.
#3

[eluser]mci[/eluser]
Thank you. Do you have a recommendation which extension or class I should use?
#4

[eluser]WanWizard[/eluser]
PECL is handy, but requires control over the PHP installation (which you might not have in all cases) so you can install it.

Alternatively, you can use this PHP function:
Code:
function gen_uuid() {
    return sprintf( 'xx-x-x-x-xxx',
        // 32 bits for "time_low"
        mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),

        // 16 bits for "time_mid"
        mt_rand( 0, 0xffff ),

        // 16 bits for "time_hi_and_version",
        // four most significant bits holds version number 4
        mt_rand( 0, 0x0fff ) | 0x4000,

        // 16 bits, 8 bits for "clk_seq_hi_res",
        // 8 bits for "clk_seq_low",
        // two most significant bits holds zero and one for variant DCE1.1
        mt_rand( 0, 0x3fff ) | 0x8000,

        // 48 bits for "node"
        mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
    );
}
( based on http://www.php.net/manual/en/function.uniqid.php#94959 )




Theme © iAndrew 2016 - Forum software by © MyBB