Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: generating unique string [duplicate]

Tags:

string

php

Possible Duplicate:
PHP: How to generate a random, unique, alphanumeric string?

I'm trying to generate unique id (alpha-numeric string). I'm using curent timestamp for that. I have two questions:

  1. Will md5(stamp1) be different from md5(stamp2) if stamp1 != stamp2.
  2. Is there a common way to generate unique string?

PS: the easiest way of cause is to take stamp as id. Still I dont want that it was easy to find out how id is generated

like image 373
Eugeny89 Avatar asked Dec 05 '22 16:12

Eugeny89


1 Answers

  1. Yes, in most cases, they will be different. Chances of hash collisions are very, very low (think one in billions).

  2. The built in function uniqid() is great for this. You could even do md5(uniqid()), but be aware, this won't increase the entropy of the GUID. For increased entropy, you can call the function like this: uniqid('',TRUE);

like image 55
xbonez Avatar answered Dec 16 '22 03:12

xbonez