<?php class TCKimlik{ private $tcKimlikNo; public function __construct($tcKimlikNo){ if((int)log($tcKimlikNo,10)!=10){ return false; } $this->tcKimlikNo = $tcKimlikNo; } function strtoupperTR($str){ $str = str_replace(array('i', 'ı', 'ü', 'ğ', 'ş', 'ö', 'ç'), array('İ', 'I', 'Ü', 'Ğ', 'Ş', 'Ö', 'Ç'), $str); return strtoupper($str); } public function validate(){ $oddSum = 0; $evenSum = 0; if(substr($this->tcKimlikNo,0,1)==0){ return false; } for($i=0;$i<=8;$i++){ if($i%2==0){ $oddSum += $this->tcKimlikNo[$i]; } else{ $evenSum += $this->tcKimlikNo[$i]; } } $tenthDigit = (($oddSum*7) - $evenSum) % 10; if($tenthDigit!=$this->tcKimlikNo[9]){ return false; } $eleventhDigit = ($oddSum + $evenSum + $tenthDigit) % 10; if($eleventhDigit!=$this->tcKimlikNo[10]){ return false; } return true; } public function askToState($ad,$soyad,$dogumYili){ if(!$this->validate()){ return false; } $client = new SoapClient('https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx?WSDL'); $result = $client->TcKimlikNoDogrula(array('TCKimlikNo'=>$this->tcKimlikNo, 'Ad'=>$this->strtoupperTR($ad), 'Soyad'=>$this->strtoupperTR($soyad), 'DogumYili'=>$dogumYili)); return $result->TCKimlikNoDogrulaResult; } }
Test için;
<?php include("tckimlik.php"); $kimlik = new TCKimlik('12345678901'); $validate = $kimlik->validate(); echo $validate; $name = ""; $familyName = ""; $birthYear = ""; $state = $kimlik->askToState($name,$familyName,$birthYear); echo $state;
Pingback: 3incidental