利用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; } }
复制代码

 

posted @   piwenfei  阅读(131)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示