Genrating a unique ID

 Question:

 
Hello Friends,

Is there any function in PHP which i can use for generating a unique ID?

Thanks




 Answers:
 

You can generate unique id's by applying this code,


$RandomStr = md5(microtime());// md5 to generate the random string
echo $ResultStr = substr($RandomStr,0,12);//trim 12 digit


There is another way of creating a unique id

First: you create a random number using this simple script


Code:
<?php
$numb = rand(1,999999999);
echo($numb);
?>


Second: You check if the number exists. If it does not exist, then, you save the new number, else, you ask the user to refresh the page to create a different ID

Ofcourse this way is a little mixed up, but it should work too
Why not Smile

Commentaires

Posts les plus consultés de ce blog

XAJAX with PHP – The future of web development

XAJAX with PHP – The future of web development

Database connection pooling in ADO.Net