
php method to generate unique id
1, PHP built-in function uniqid()
uniqid Used to obtain a prefixed unique ID based on the current time in microseconds.
uniqid ([ string $prefix = "" [, bool $more_entropy = false ]] ) : string
Note: This function does not guarantee the uniqueness of the return value. Since most systems use NTP or similar services to adjust the system's time, system time changes frequently. Additionally, the process/thread may not return a unique ID. Use more_entropy to increase the probability of uniqueness.
The following method returns similar results: 5DDB650F-4389-F4A9-A100-501EF1348872
function uuid() {
if (function_exists ( 'com_create_guid' )) {
return com_create_guid ();
} else {
mt_srand ( ( double ) microtime () * 10000 ); //optional for php 4.2.0 and up.随便数播种,4.2.0以后不需要了。
$charid = strtoupper ( md5 ( uniqid ( rand (), true ) ) ); //根据当前时间(微秒计)生成唯一id.
$hyphen = chr ( 45 ); // "-"
$uuid = '' . //chr(123)// "{"
substr ( $charid, 0, 8 ) . $hyphen . substr ( $charid, 8, 4 ) . $hyphen . substr ( $charid, 12, 4 ) . $hyphen . substr ( $charid, 16, 4 ) . $hyphen . substr ( $charid, 20, 12 );
//.chr(125);// "}"
return $uuid;
}
}2, md5(time() . mt_rand(1,1000000));
This method has a certain probability of duplication
The above is the detailed content of How to generate unique id in php. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function






