PHP Verified ID Number

Source: Internet
Author: User
This article we share with you the PHP authentication ID number of knowledge, is also a small technology, hope to help everyone.

Structure of the ID card number

Identity card number is a feature combination code, consisting of 17-bit digital body code and a check code.

Order from left to right according to this: six-digit address code, eight-digit birth date code, three-bit digital sequence code and a digit check code .


Address code (first six digits)

The Code of administrative divisions in the county (city, Flag, district) of the permanent residence of the coded object shall be executed according to gb/t2260.


Date-of-Birth code (seventh to 14)

Represents the year, month, and day of the birth of the encoded object, executed according to gb/t7408, with no separator between the year, month, and day code.


Sequential code (15th to 17 bits)

Indicates the range of the area identified by the same address code, the sequence number of the same year, the same month, the same day birth, the sequence code is assigned to men, odd numbers are assigned to women.


Check code (18th digit number)

1. Weighted summation formula for 17-bit digital body code

s= sum (Ai * Wi), i=0, ..., 16, the first 17 digits of the right sum.

Ai: A numeric value representing the ID number at position i

Wi: Indicates the weighting factor at position I

Wi:7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2


2. Calculation mode

Y = mod (S, 11)


3. Get the corresponding check code by the module

Y:0 1 2 3 4 5 6 7 8 9 10

Check code: 1 0 X 9 8 7 6 5 4 3 2

To verify the ID number method:

[PHP] view plain copy

<?php function Checkidcard ($idcard) {//can only be 18-bit if (strlen ($idcard)!=18) {     return false;      }//Remove the ontology code $idcard _base = substr ($idcard, 0, 17);      Remove the check code $verify _code = substr ($idcard, 17, 1);      Weighted factor $factor = Array (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);      Parity codes correspond to values $verify _code_list = Array (' 1 ', ' 0 ', ' X ', ' 9 ', ' 8 ', ' 7 ', ' 6 ', ' 5 ', ' 4 ', ' 3 ', ' 2 ');      Check code $total = 0 based on the first 17 digits;      for ($i =0; $i <17; $i + +) {$total + = substr ($idcard _base, $i, 1) * $factor [$i];      }//modulo $mod = $total% 11;      Compare check codes if ($verify _code = = $verify _code_list[$mod]) {return true;      }else{return false;  }} $idcard = ' Fill in the ID number to be verified here ';  Var_dump (Checkidcard ($idcard)); 

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.