PHP generates a 8-digit unique activation code

Source: Internet
Author: User

    /** * Generate activation Code **/    functionShowgenerationactivationcode () {#Channel type ID        $channel _id=$_post[' Channel ']; #query channel name according to channel ID        $channelInfo= Load_mysql ("Channelinfo" ); $_res=$channelInfo->getinfobyid ($channel _id); $en _name=$_res[' En_name ']; #type of activity        $type=$_post[' Active_type ']; #number of builds        $nub=$_post[' Nub ']; #an array that accepts the generated activation code        $array _activationcode=$this->showunique_rand (10000000,99999999,$nub); #Generate code Array        $code _array=$this->showalgorithm_activationcode ($type,$channel _id,$array _activationcode); #Connect to Redis         $redis=NewRedis (); $redis->connect (' 192.168.1.131 ', 8899); //Authorized         $redis->auth ("funova2014"); }    /** * Generate code algorithm *TYPE: Activity type [fetch top three] *channel_id: Channel id[take top three bits, not 0 padding] *array_activationcode: Activation code array *code algorithm format = activity type + Channel    Tao Id+array_activationcode; An array of *return code*/    functionShowalgorithm_activationcode ($type,$channel _id,$array _activationcode){         #intercept activity type front bit string         $type=MB_SUBSTR ($type, 0,3, ' Utf-8 '); #Channel id[take top three, insufficient left with 0 padding]         $channel _id=Str_pad($channel _id, 3, ' 0 ',str_pad_left); #define an array of code algorithms         $code _array=Array();  for($i= 0;$i<Count($array _activationcode);$i++){             $code _array[$i]=$type.‘‘.$channel _id.‘‘.$array _activationcode[$i]; }        return  $code _array; }    /** * Generate 8-digit activation code algorithm*/    functionShowunique_rand ($min,$max,$num) {       $count= 0; $return=Array();  while($count<$num) {        $return[] =Mt_rand($min,$max); $return=Array_flip(Array_flip($return)); $count=Count($return); }      return $return; }

PHP generates a 8-digit unique activation code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.