<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<title>身分证字号产生器</title>
</head>
<body>
<?php
class idCard_check{ //宣告一个类别,来送出身分证字号检查码
var $id; //放检查码用的
var $idx = array(1,1,1,1,1,1,1,1,3,1,1,2,2,2,3,2,2,2,2,2,2,2,3,3,3,3); //这两个阵列,是用来把字母转成数字用的
var $idy = array(0,1,2,3,4,5,6,7,4,8,9,0,1,2,5,3,4,5,6,7,8,9,0,1,2,3); //ex. A=10, Z=33, I=34 ..etc
function check($id_no){
$id_no=ucfirst($id_no); //把字母转成大写
for($i=0;$i<10;$i++) $ch[$i] = substr($id_no,$i,1); //把身分证字号转成列阵
$d=0; //判断字母的位置,用来看$idx和$idy的对应值,例如Z的位置,在idx跟idy里头,就是3跟3
for($char="A";$char!=$ch[0];$char++){$d++;}//同上
//下面那一行是用来实现身分证码的演算法
$id_num=$this->idx[$d]+$this->idy[$d]*9+$ch[1]*8+$ch[2]*7+$ch[3]*6+$ch[4]*5+$ch[5]*4+$ch[6]*3+$ch[7]*2+$ch[8]*1;
//下面是把数字除以10后求余数
$id=$id_num%10;
//下面是把余数用10减掉,求出检查码
$id=10-$id;
if($id==10){
return 0;
}else{
return $id;
}
}
}
//下面两行是设定乱数种子
mt_srand((double)microtime()*1000000);
srand((double)microtime()*1000000);
//
//下面是用来排列A~Z
$alpha_string=array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
$str="";
$str.=$alpha_string[array_rand($alpha_string,1)]; //乱数求出阵列的索引值
//
$str.=rand(1,2); //求男生,求女生(听起来像拜注生娘娘....)
//
for($i=0;$i<8;$i++) $str.=mt_rand(0,9);//增加后面的八码流水号
$tempCheck=new idCard_check;//宣告类别
$result=$tempCheck->check($str);//使用类别中的方法,回传「正确的」余数
$string.=substr_replace($str,$result,9);//把身分证码最后一个字元取换成我们算出来的余数
//这样就有正确的身分证字号了
//
echo "<font color='red' size=ཆ'>".$string."</font>";
?>
<form name="idmaker" method="POST" action="idMaker.php">
<input type="submit" value='产生身分证字号'>
</form>
</body>
</html>