标签:
<?php //生日就不用说了,号码前6位可判断地区 //前17位依次乘以此17位数字 总合除以11,余数为身份证最后一位数字(10=2,2=X)此两个数字除外 $arr = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; $result = [0, 1, 10, 3, 4, 5, 6, 7, 8, 9, ‘X‘=>2]; $code = trim($_GET[‘code‘]); $count = 0; foreach ($arr as $key => $val) { $num = substr($code, $key, 1); $count += $num * $val; if($key == 16) $sex = $num; } $n = intval($count % 11); $a = substr($code, -1, 1); if (!in_array($n, $result) || array_flip($result)[$n] != strtoupper($a)) { die(‘身份证不合法‘); } if($sex%2==0) echo ‘性别女,‘; else echo ‘性别男,‘; echo ‘合法‘; ?>
标签:
原文地址:http://my.oschina.net/tanwen/blog/520642