I have a unique identifier for client i generate everytime a client request a service support.
once the id is generate, the id is inserted in the database
here my code:
function makeUnique() {
$start_time = uniqid(microtime(1));
$duration = sprintf('%0.24f', $start_time);
return date('dmYHis').$duration;
}
echo makeUnique();
this output: 071120112032291320715949.928639888763427734375000
for some reason i get 071120112032291320715949 as the number. what am i doing wrong?
you need to remove the "." (dot) in your function. you are probably using an INT which remove numbers after the dot.
return str_replace('.', '', date('dmYHis').$duration);
and make sure the field is big enough - like varchar(50)
my recommendation will be to simply hash the client id using md5
md5($clientid)
and you have the mysql field as a char(32)
You've already got your solution in your code. The php function uniqid() provides... well, a unique ID. If you want to ensure it's really really really really unique (though it's not necessary), just append time() to the end, like so:
return uniqid().time();
This would also return letters mixed in with numbers (higher entropy), like this response:
4eb8895a76edc1320716634
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With