0

What I want is upload an image, get unique ID and save this in server. I have two methods to get ID and I want to know if this is the right path for real application.

method 1

round(microtime(true));

method 2

md5(uniqid(rand(), true));

glen
  • 3
  • 1
  • 7

2 Answers2

0

UPDATE: Use cryptographic-ally unique id - uuidV4 to gaureente uniqueness

https://stackoverflow.com/a/31460273/3359432

You can use PHP inbuilt function uniqid. Available since PHP 4

Quoting from PHP official site

<?php
/* A uniqid, like: 4b3403665fea6 */
printf("uniqid(): %s\r\n", uniqid());

/* We can also prefix the uniqid, this the same as 
 * doing:
 *
 * $uniqid = $prefix . uniqid();
 * $uniqid = uniqid($prefix);
 */
printf("uniqid('php_'): %s\r\n", uniqid('php_'));

/* We can also activate the more_entropy parameter, which is 
 * required on some systems, like Cygwin. This makes uniqid()
 * produce a value like: 4b340550242239.64159797
 */
printf("uniqid('', true): %s\r\n", uniqid('', true));
?>

http://php.net/manual/en/function.uniqid.php

You must also read the warning

Warning This function does not guarantee uniqueness of return value. Since most systems adjust system clock by NTP or like, system time is changed constantly. Therefore, it is possible that this function does not return unique ID for the process/thread. Use more_entropy to increase likelihood of uniqueness.

Nidhin David
  • 2,426
  • 3
  • 31
  • 45
  • Yes I 'am aware of this that's why I seek advice if my methods gonna work 100% uniqueness. – glen Nov 29 '17 at 06:22
0

Yes Sure You Can Use Md5 with current date and time