Unique, secured and short id using php. Possible?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kigoobe
    New Member
    • May 2007
    • 67

    #1

    Unique, secured and short id using php. Possible?

    Well guys

    I need a way to get an unique id using php. For the moment, I have learned that the best way to get an unique ID is to put together time() and server address. Then, for additional security we can use additional strings, sha1, md5, etc.

    Problem, the result that I got is quite long. Is it possible to get something that is short, but unique and secured at the same time?

    Thanks. :)
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    have you tried using rand()?

    Comment

    • kigoobe
      New Member
      • May 2007
      • 67

      #3
      Thanks mark. But what would be the possibility for two person to get the same number, using rand() only. It seems that there's a danger, isn't it?

      Comment

      • kigoobe
        New Member
        • May 2007
        • 67

        #4
        OK, I am doing it with rand() + mysql_insert_id . :)

        Thanks Mark.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by kigoobe
          Thanks mark. But what would be the possibility for two person to get the same number, using rand() only. It seems that there's a danger, isn't it?
          It is.. but only a little chance that would happen.

          And just to make sure that it wasn't a duplicate you could compare the id against the ones already in the db and if there's a match you could create a new one.

          Originally posted by kigoobe
          OK, I am doing it with rand() + mysql_insert_id . :)

          Thanks Mark.
          No probs :)

          Comment

          Working...