» » Use PHP generate a unique membership number

 

Use PHP generate a unique membership number

Author: bamboo06 on 4-11-2014, 03:55, views: 10295

40
When we want a huge number of data, while the median number have restrictions, such as license plate numbers 5, 10 of a document number, serial number of orders, short URL, etc., we can use the 36-ary calculated not repeat the numbers in line with the median.

We will use 0-Z (0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ) to represent the values ​​0-35, such as the letter Z represents 35. So I want to get a five numbers, the greatest amount of information is 36 5 th, and 36 ^ 5 = 60,466,176, which is equivalent to the maximum number of five decimal numbers: 60466176.
In order to do presentations in this article, we assume that a group of 10 paid a club membership number, membership number by three city ID card encoding +2 +5 bit checksum components. City number with area code indicated as 755 representatives of Shenzhen, five card numbers from card number consisting of 36 hexadecimal, followed by two check code is generated by a certain algorithm is able to use the checksum to verify the card number legitimacy. In this case, we generate 10 card number corresponds to the maximum to meet the 60 million membership number, and is not repeated unique card number.
PHP
We use PHP to convert hexadecimal, decimal turn 36 hex.

class Code { 
    //Password dictionary
    private $dic = array( 
        0=>'0',    1=>'1', 2=>'2', 3=>'3', 4=>'4', 5=>'5', 6=>'6', 7=>'7', 8=>'8',     
        9=>'9', 10=>'A',  11=>'B', 12=>'C', 13=>'D', 14=>'E', 15=>'F',  16=>'G',  17=>'H',     
        18=>'I',19=>'J',  20=>'K', 21=>'L',  22=>'M',  23=>'N', 24=>'O', 25=>'P', 26=>'Q',     
    27=>'R',28=>'S',  29=>'T',  30=>'U', 31=>'V',  32=>'W',  33=>'X', 34=>'Y', 35=>'Z' 
    ); 
 
 
    public function encodeID($int, $format=8) { 
        $dics = $this->dic; 
        $dnum = 36; //Hexadecimal number
        $arr = array (); 
        $loop = true; 
        while ($loop) { 
            $arr[] = $dics[bcmod($int, $dnum)]; 
            $int = bcdiv($int, $dnum, 0); 
            if ($int == '0') { 
                $loop = false; 
            } 
        } 
        if (count($arr) < $format) 
            $arr = array_pad($arr, $format, $dics[0]); 
 
        return implode('', array_reverse($arr)); 
    } 
 
    public function decodeID($ids) { 
        $dics = $this->dic; 
        $dnum = 36; //Hexadecimal number
        //Key exchange 
        $dedic = array_flip($dics); 
        //Go to zero 
        $id = ltrim($ids, $dics[0]); 
        //trun 
        $id = strrev($id); 
        $v = 0; 
        for ($i = 0, $j = strlen($id); $i < $j; $i++) { 
            $v = bcadd(bcmul($dedic[$id { 
                $i } 
            ], bcpow($dnum, $i, 0), 0), $v, 0); 
        } 
        return $v; 
    } 
 
} 

We define the Code class, define a password dictionary, namely 0-Z corresponding numerical method encodeID ($ int, $ format) in the parameter $ int represents a number, $ format represents the median length, for example encodeID (123456789,5) expressed will be converted into five figures 123456789 36 hexadecimal numbers and methods decodeID ($ ids) is used to convert 36 hex number 10 hex number.
We can do to generate the card:
$code = new Code(); 
$card_no = $code->encodeID(888888,5); 

As above, we can get a five card number, it actually represents the card number is 888888 (6 8), membership number, but the actual conversion is five numbers: 0J1VC.
Next, we check the number and the city code plus the city ID is already defined, the check code through a certain algorithm to obtain, in this case, we use a simple algorithm: The first three numbers and five cities md5 card numbers were encrypted, and then take the first two as md5 checksum value, so get the numbers behind the two checksum.

$card_pre = '755'; 
$card_vc = substr(md5($card_pre.$card_no),0,2); 
$card_vc = strtoupper($card_vc); 
echo $card_pre.$card_no.$card_vc; 

Practical applications, you can get 10 hexadecimal numbers through a database to ensure that Unique numbers, then use the above code combinations, and ultimately generate a 10-bit card number is not repeated.

Category: PHP Scripts / Javascript

Dear visitor, you are browsing our website as Guest.
We strongly recommend you to register and login to view hidden contents.
<
  • 0 Comments
  • 0 Articles
27 December 2017 02:37

AllMailinfo

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Create AOL mail

<
  • 0 Comments
  • 0 Articles
15 January 2018 15:20

Jude Rowlands

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
<
  • 0 Comments
  • 0 Articles
17 January 2018 04:59

Avast Premier Keygen

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
<a href="https://keycracked.com/avast-premier-keygen-license-key">Avas
t Premier Keygen</a>Nice article. Waiting for your next article. Thank you.

<
  • 0 Comments
  • 0 Articles
18 January 2018 07:12

shahed

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Amazing post.
Vuescan Crack

<
  • 0 Comments
  • 0 Articles
18 January 2018 16:24

Dreamweaver Crack

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
<a href="https://keycracked.com/adobe-dreamweaver-crack">Dreamweaver Crack</a> Nice tutorial.

<
  • 0 Comments
  • 0 Articles
20 January 2018 16:54

Escorts in Kolkata

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Beauti Queen amazing kolkata escorts agency alwyas ready for you at your doorstep. Beauti Queen provide you high profile independent girl in kolkata, escorts service in kolkata, kolkata escorts. If you are looking for the ultimate encounter in Kolkata then I am your sophisticated young Kolkata escorts that provides upscale companionship for making your night becomes true.
Kolkata Escorts Escorts in Kolkata

<
  • 0 Comments
  • 0 Articles
29 January 2018 10:18

Escorts in Kolkata

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Renu Das Kolkata Escorts Services has gorgeous females provides Independent Escorts Service in Kolkata call girls at 100% satisfaction with VIP models. Provided Kolkata escorts at our agency are professional in nature and are eager to serve you at your place.
kolkata escorts, escorts in kolkata, escorts service in kolkata, female escorts in kolkata, escorts agency in kolkata, independent escorts in kolkata

<
  • 0 Comments
  • 0 Articles
2 February 2018 19:25

Kolkata Escorts

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Renu Das Kolkata Escorts Services has gorgeous females provides Independent Escorts Service in Kolkata call girls at 100% satisfaction with VIP models. Provided Kolkata escorts at our agency are professional in nature and are eager to serve you at your place.
kolkata escorts, escorts in kolkata, escorts service in kolkata, female escorts in kolkata, escorts agency in kolkata, independent escorts in kolkata

<
  • 0 Comments
  • 0 Articles
27 February 2018 01:42

Delhi Escorts

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Riya Chaudhary is an Independent Delhi Escort girl, who offers dazzling hot Delhi Escorts Service, incall or outcall services both to complete your dreams in real entertainment. We offers high class Independent Escorts in Delhi at Riya Chaudhary Delhi Escorts service agency for elite peoples in the city to avail ultimate satisfaction. you can spend your beautiful moments.
delhi escorts, independent escorts in delhi, escorts in delhi

<
  • 0 Comments
  • 0 Articles
28 February 2018 20:18

Lucky patcher

Reply
  • Group: Guests
  • РRegistered date: --
  • Status:
 
Very Nice and good information great job thank you for sharing lucky patcher apk no root

Previous Next
Information
Comment on the news site is possible only within (days) days from the date of publication.