• PHP+Jquery+Ajax 实现动态生成GUID、加载GUID


    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 值。

    特点:

    • 需要GUID的时候,可以完全由算法自动生成,不需要一个权威机构来管理。
    • 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="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/articles/6511141.html

  • 相关阅读:
    gitlab: git clone/pull / push: The project you were looking for could not be found
    转载: MySQL启动出错InnoDB: Check that you do not already have another mysqld process解决方法
    root用户删除文件,提示:Operation not permitted
    使用dockerfile打包新镜像
    kubernets创建Deployment
    代理全家福
    Spring事务传播详解
    [FFmpeg]Centos7 yum安装
    [Redis]存放字典
    [Docker]开放2375端口
  • 原文地址:https://www.cnblogs.com/hollow/p/6511141.html
Copyright © 2020-2023  润新知