利用session生成唯一自增4位数数字

<?php
define("TODAY_DATE", date('y') . date('m') . date('d'));

class StringTools { private static $StringTools; private function __construct(){} private function __clone(){} public static function getStringTools(){ if(!self::$StringTools instanceof self){ self::$StringTools = new self(); } return self::$StringTools; } public static function makeCode() { if (isset($_SESSION['mt_rand_num']) && TODAY_DATE == $_SESSION['mt_rand_num']['date']) { $_SESSION['mt_rand_num']['num'] = intval($_SESSION['mt_rand_num']['num'] + 1); $res = TODAY_DATE . sprintf("%04d", $_SESSION['mt_rand_num']['num']); } else { $mt_rand_num['date'] = TODAY_DATE; $mt_rand_num['num'] = 1; $_SESSION['mt_rand_num'] = $mt_rand_num; $res = TODAY_DATE . sprintf("%04d", $mt_rand_num['num']); } return $res; } }

 

上一篇:随机数模板


下一篇:Matlab基于加权变异的粒子群优化算法(WVPSO)