zoukankan      html  css  js  c++  java
  • genToken- Php file

     1  <?php
     2 
     3  
     4 
     5  public function genToken($len = 32, $md5 = true) {
     6         # Seed random number generator
     7         # Only needed for PHP versions prior to 4.2
     8         mt_srand((double) microtime() * 1000000);
     9         # Array of characters, adjust as desired
    10         $chars = array(
    11             'Q', '@', '8', 'y', '%', '^', '5', 'Z', '(', 'G', '_', 'O', '`',
    12             'S', '-', 'N', '<', 'D', '{', '}', '[', ']', 'h', ';', 'W', '.',
    13             '/', '|', ':', '1', 'E', 'L', '4', '&', '6', '7', '#', '9', 'a',
    14             'A', 'b', 'B', '~', 'C', 'd', '>', 'e', '2', 'f', 'P', 'g', ')',
    15             '?', 'H', 'i', 'X', 'U', 'J', 'k', 'r', 'l', '3', 't', 'M', 'n',
    16             '=', 'o', '+', 'p', 'F', 'q', '!', 'K', 'R', 's', 'c', 'm', 'T',
    17             'v', 'j', 'u', 'V', 'w', ',', 'x', 'I', '$', 'Y', 'z', '*'
    18         );
    19         # Array indice friendly number of chars;
    20         $numChars = count($chars) - 1;
    21         $token = '';
    22         # Create random token at the specified length
    23         for ($i = 0; $i < $len; $i++)
    24             $token .= $chars[mt_rand(0, $numChars)];
    25         # Should token be run through md5?
    26         if ($md5) {
    27             # Number of 32 char chunks
    28             $chunks = ceil(strlen($token) / 32);
    29             $md5token = '';
    30             # Run each chunk through md5
    31             for ($i = 1; $i <= $chunks; $i++)
    32                 $md5token .= md5(substr($token, $i * 32 - 32, 32));
    33             # Trim the token
    34             $token = substr($md5token, 0, $len);
    35         } 
    36         
    37         return $token;
    38     }
    39     
  • 相关阅读:
    mysql字符集和数据库引擎修改方法
    android 之GridView和ImageView教程
    把php代码保存到php文件实现方法
    extjs gridpanel 操作行 得到选中行的列
    SQL 分页
    vs 调试 慢 解决办法
    JS获取屏幕高度
    C#事件以及委托
    ExtJs 3.0 不兼容 IE9
    ASP.NET 获取客户端IP (无视代理)
  • 原文地址:https://www.cnblogs.com/it80/p/4919906.html
Copyright © 2011-2022 走看看