bluezz旅遊筆記本

附近

身分證字號檢查php



看google圖片

server端的身分證號碼認證可以防止有效防止使用者造假

建立日期:2007-05-15 
更新日期:2007-05-15
php身分證字號檢查source code
<p align="center"><font color="black">身分證字號檢查</font>

<center>
<form method="post">
        請輸入身分證號碼
          <input type="text" name="identity">
          <input name="act" type="submit" value="檢查" />
  <br> <br><hr width="80%">
</form>
<br>
<?
// 身分證檢查函數
function check_identity($id) {
$flag = false;
$id=strtoupper($id);
$d0=strlen($id);
$qd="";
if ($d0 <= 0) {$qd=$qd."還沒填呢 !n";}
if ($d0 > 10) {$qd=$qd."超過10個字 !n";}
if ($d0 < 10 && $d0 > 0) {$qd=$qd."不滿10個字 !n";}
$d1=substr($id,0,1);
$ds=ord($d1);
if ($ds > 90 || $ds < 65) {$qd=$qd."第一碼必須是大寫的英文字母 !n";}
$d2=substr($id,1,1);
if($d2!="1" && $d2!="2") {$qd=$qd."第二碼有問題 !n";}
for ($i=1;$i<10;$i++) {
$d3=substr($id,$i,1);
$ds=ord($d3);
if ($ds > 57 || $ds < 48) {$n=$i+1;$qd=$qd."第二到十碼有問題 !n";
break;}
}
$num=array("A" => "10","B" => "11","C" => "12","D" => "13","E" => "14",
"F" => "15","G" => "16","H" => "17","J" => "18","K" => "19","L" => "20",
"M" => "21","N" => "22","P" => "23","Q" => "24","R" => "25","S" => "26",
"T" => "27","U" => "28","V" => "29","X" => "30","Y" => "31","W" => "32",
"Z" => "33","I" => "34","O" => "35");
$n1=substr($num[$d1],0,1)+(substr($num[$d1],1,1)*9);
$n2=0;
for ($j=1;$j<9;$j++) {
$d4=substr($id,$j,1);
$n2=$n2+$d4*(9-$j);
}
$n3=$n1+$n2+substr($id,9,1);
if(($n3 % 10)!=0) {$qd=$qd."不通過 !n";}
if ($qd=="") {$flag = true;}
return $flag;
}
// 結束
$identity = $_REQUEST["identity"];
if($identity){
echo $identity;
if(check_identity($identity)){
echo "您的身分證字號<font color=blue></font>沒問題!";
}else{
echo "您的身分證字號<font color=red></font>有問題!";
}
}
?>
<br />程式修改by <a href="http://bluezz.tw">http://bluezz.tw</a>

php檔案身分證字號檢查
UTF-8版
fileidentity.php
( 1.83 KB )