Skip to content

Instantly share code, notes, and snippets.

@yusureabc
Created November 22, 2017 02:23
Show Gist options
  • Save yusureabc/416e9e88ff35ac5d5dd68f56e2858d86 to your computer and use it in GitHub Desktop.
Save yusureabc/416e9e88ff35ac5d5dd68f56e2858d86 to your computer and use it in GitHub Desktop.
PHP生成uuid
<?php
function uuid($prefix = '')
{
$chars = md5(uniqid(mt_rand(), true));
$uuid = substr($chars,0,8) . '-';
$uuid .= substr($chars,8,4) . '-';
$uuid .= substr($chars,12,4) . '-';
$uuid .= substr($chars,16,4) . '-';
$uuid .= substr($chars,20,12);
return $prefix . $uuid;
}
echo uuid();
echo '<br/>'.session_create_id();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment