Saturday, May 17, 2008

Generating unique id in php

Hey people.

I had gone to a interview some years back and the interviewer had asked me a question about how does one generate an uuid in php and at that time i never used or knew there was something like uniqid function in php as i used to generate a uuid myself combining various unique parameters from a web request.Then that guy told me he has a good alternative to my code and it takes less lines of codes.I now use this function often as it suits my purpose.

So lets see how we can generate a uuid in php .

$getmy_uuid=md5(uniqid(rand(),true));

?>

Thats all isn't that a kewl single line of code.To know what the uniqid parameters are
read this article http://in.php.net/manual/en/function.uniqid.php.

0 comments: