Page 1 of 1

creating a unique id

Posted: Fri Apr 24, 2009 12:59 pm
by jazz090
i need to create a unique id with php and i dont wanna use uniqid() could i possibly convert it to base 10 and still get the same exclusive results?

Re: creating a unique id

Posted: Fri Apr 24, 2009 2:34 pm
by McInfo
If you are just looking for a base-10 equivalent of uniqid(),

Code: Select all

base_convert(uniqid(), 16, 10)
Here is a script that shows how the base-16 unique ID and its base-10 equivalent are related, and also how the ID is related to time.

Code: Select all

<?php
header('Content-Type: text/plain');
for ($i = 0; $i < 50; $i++)
{
    $uid = uniqid();
    echo $uid . ' : ' . base_convert($uid, 16, 10) . "\n";
}
?>
Edit: This post was recovered from search engine cache.