Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-23-2005, 01:36 PM Unique ID
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Hi everyone.

I'd like to know if the use of timestamp as a unique id is a good or bad idea.

I am already using an autoincrement, but i need something in addition to that.

Furthermore, i would like to know what would happen if two users on two different computers both submitted a statement at exactly the same time. Would the timestamps be different to each other and therefore unique, or is there a possibility that they might collide?

Thanks for your help.
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
 
Register now for full access!
Old 03-23-2005, 02:14 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
They could certainly collide as improbable as that is. However, if you are looking for something unique, try the hash of a string appending the IP, a timestamp and a random number.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 03-23-2005, 02:18 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Hi Kyrnt.

Thanks for the reply.

What exactly is the hash of a string appending the ip?
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Old 03-23-2005, 03:57 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
fambi,

The IP address of your user can be extracted in a PHP script using $_SERVER[REMOTE_ADDR]. It is just a string. microtime() returns the current time. md5() is a common hash function that can be used to convert a string into a 32-bit hexadecimal number.

So here is a function to create the uniqueID you mentioned. I can't test it where I am, but anytime you need a unique identifier, just call this method and the chances are astronomical that you would ever receive two identical uniqueIDs.


PHP Code:

function getUniqueID()
{
    return 
md5$_SERVER[REMOTE_ADDR] . microtime() );

__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 03-23-2005, 10:52 PM
fambi's Avatar
Ultra Talker

Posts: 339
Trades: 0
Thanks again. I think it will do fine!
__________________

Please login or register to view this content. Registration is FREE
from a
Please login or register to view this content. Registration is FREE
is easy!
Read this
Please login or register to view this content. Registration is FREE
that uses our
Please login or register to view this content. Registration is FREE
.
fambi is offline
Reply With Quote
View Public Profile Visit fambi's homepage!
 
Reply     « Reply to Unique ID
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20711 seconds with 12 queries