Jump to content

[SOLVED] UniqueID function - would uniqueID ever be repeated?


Recommended Posts

When using the function uniqueid, does it create a uniqueid that will never be repeated?  In order to do this, I assume it would have to base an id on the date and the time?

 

Also, just to make extra sure, is there any way to store the uniqueID in a table plus have the auto_increment number 1,2,3,etc?

 

In other words, store 1+uniqueID, 2+uniqueID, 3+uniqueID, 4+uniqueID in a table.

In doing so, would it be possible to have duplicates?

 

I'm using wamp server phpadmin 5.2.6

md5(microtime()); will give you a unique ID.  The chances that 2 ids are generated at the same microsecond are, well, almost impossible.

 

Yes you can store it in a database as you described...why couldn't you?

 

If you are worried about duplicates and are storing the id in a table, you could always query the table to see if the id already exists, but using the method above with microtime you shouldn't need to do it.

md5(microtime()); will give you a unique ID.  The chances that 2 ids are generated at the same microsecond are, well, almost impossible.

 

Yes you can store it in a database as you described...why couldn't you?

 

If you are worried about duplicates and are storing the id in a table, you could always query the table to see if the id already exists, but using the method above with microtime you shouldn't need to do it.

 

Is that just based on the time, and not the date?

uniqid() is also based on the date/time to the microsecond, but can add entropy and pseudo-random prefixing. I'd suggest using that, or MySQL's UUID() function over md5( microtime() )

 

So, uniquid() will never ever repeat?

And its pretty much the same as microtime?

 

What is entropy and pseudo-random prefixing?

 

 

Entropy, to put it simply

A measure of the level of disorder or randomness in a closed system.

 

Random prefix is just that... a random string that's prefixed in front of the ID...

 

$uid = uniqid( md5(mt_rand()), TRUE );

 

Though slightly slower, the chances of a collision are extremely unlikely... even if you have several executions in a millisecond.

Of course, I was thinking, I could just have the ID be auto_increment (1,2,3,4,5,etc)....

that insures that every entry is unique.

 

 

Then just attach some word to the value.

So then every value will be example:

1keyword, 2keyword, 3keyword, 4keyword, 5keyword

 

That will insure that people can't guess it....

 

Then md5 that value and store that in the cookie.

 

It would be unique and it would be very difficult for people to guess it, unless they found out my keyword.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.