creating a unique id

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

creating a unique id

Post 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?
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: creating a unique id

Post 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.
Post Reply