GUID:
全局唯一标识符(GUID,Globally Unique Identifier)是一种由算法生成的二进制长度为 128 位的数字标识符。GUID 主要用于在拥有多个节点、多台计算机的网络或系统中。在理想情况下,任何计算机和计算机集群都不会生成两个相同的 GUID。GUID 的总数达到了 2^128(3.4×10^38)个,所以随机生成两个相同 GUID 的可能性非常小,但并不为 0。GUID 一词有时也专指微软对 UUID 标准的实现。
格式:
GUID 的格式为 "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",其中每个 x 是 0-9 或 a-f 范围内的一个 4 位。例如:768ECC9F-F27F-7325-28A0-C3DA8054420A 即为有效的 GUID 值。
特点:
PHP 生成 GUID:
- 1 php
- 2
- 3 function create_guid()
- 4 {
- 5 $str = strtoupper(md5(uniqid(mt_rand().true)));
- 6
- 7 $line = chr(45);
- 8
- 9 $guid = substr($str,6,2).substr($str,4,2).substr($str,2,2).substr($str,0,2).$line.substr($str,10,2).substr($str,8,2).$line.substr($str,14,2).substr($str,12,2).$line.substr($str,16,4).$line.substr($str,20,12);
- 10
- 11 return $guid;
- 12
- 13 }
- 14
- 15
- 16 echo json_encode(create_guid());
- 17
- 18 ?>
html 通过 AJAX 动态加载 GUID:
- 1 <!DOCTYPE html>
- 2 <html>
- 3 <head>
- 4 <meta charset="utf-8" />
- 5 <title>PHP+Jquery+Ajax 实现动态生成GUID、加载GUID</title>
- 6 <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
- 7 <script type="text/javascript">
- 8 $(function(){
- 9 $("#getGuid").click(function(){
- 10 $.ajax({
- 11 type:"post",
- 12 url:"guid.php",
- 13 async:true,
- 14 success:function(data){
- 15 data = JSON.parse(data);
- 16 $("#guid").val(data);
- 17 },
- 18 dataTye:'json'
- 19 });
- 20 });
- 21
- 22 });
- 23 </script>
- 24 </head>
- 25 <body>
- 26 GUID:
- 27 <input type="text" id="guid" value="" style="width:300px;text-align:center;border:0px;border-bottom:1px solid #8c8c8c;"/>
- 28 <input type="button" id="getGuid" value="GET GUID" />
- 29 </body>
- 30 </html>
来源: http://www.cnblogs.com/hollow/p/6511141.html