This repository has been archived by the owner on Mar 28, 2021. It is now read-only.
/
TcCheck.php
116 lines (99 loc) · 2.98 KB
/
TcCheck.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php namespace Juy\TcCheck;
/**
* @author Sevdin Filiz <angelside@users.sourceforge.net>
* @copyright (c) Juy Software <http://juysoft.com>
*/
/**
* T.C. Kimlik numarası doğrulama ve sorgulama
*/
class TcCheck {
/**
* T.C. kimlik numarası algoritmik doğrulama
*
* // Kullanım
$check = TcCheck::verify($bilgi['tckimlikno']);
var_dump($check);
*
* @param int $tcno
* @return bool
*/
public static function verify($tcno)
{
// 11 karakterden oluşmalıdır
if (strlen($tcno) != 11)
{
return false;
}
// Rakamlardan oluşmalıdır
if (!preg_match('/(?<!\S)\d++(?!\S)/', $tcno))
{
return false;
}
// Algoritmik hesaplamalar
$digit = preg_split('//', $tcno, -1, PREG_SPLIT_NO_EMPTY);
if ($digit[0] == 0)
{
return false;
}
$odd = $digit[0] + $digit[2] + $digit[4] + $digit[6] + $digit[8];
$even = $digit[1] + $digit[3] + $digit[5] + $digit[7];
$digit10 = ($odd * 7 - $even) % 10;
$total = ($odd + $even + $digit[9]) % 10;
if ($digit10 != $digit[9] or $total != $digit[10])
{
return false;
}
return true;
}
/**
* API üzerinden T.C. Kimlik numarası veri doğruluk kontrolü
*
* // Kullanım
$data = array(
'tcno' => 'xxxxxxxxxxx', // T.C. kimlik Numarası (11 haneli ve rakamlardan oluşmaladır)
'isim' => 'XXXXX', // Doğrulanacak kişinin adı, tümü büyük harf (iki isme sahip kişilerin iki ismide yazılmalı)
'soyisim' => 'XXXXX', // Doğrulanacak kişinin soyadı, tümü büyük harf
'dogumyili' => '19xx', // Doğum yılı (4 haneli ve rakamlardan oluşmalıdır)
);
$check = TcCheck::check($data);
var_dump($check);
*
* @param array $data
* @return bool
*/
public static function check($data)
{
$post_data = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<TCKimlikNoDogrula xmlns="http://tckimlik.nvi.gov.tr/WS">
<TCKimlikNo>'.$data['tcno'].'</TCKimlikNo>
<Ad>'.$data['isim'].'</Ad>
<Soyad>'.$data['soyisim'].'</Soyad>
<DogumYili>'.$data['dogumyili'].'</DogumYili>
</TCKimlikNoDogrula>
</soap:Body>
</soap:Envelope>';
$ch = curl_init();
// CURL options
$options = array(
CURLOPT_URL => 'https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post_data,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => array(
'POST /Service/KPSPublic.asmx HTTP/1.1',
'Host: tckimlik.nvi.gov.tr',
'Content-Type: text/xml; charset=utf-8',
'SOAPAction: "http://tckimlik.nvi.gov.tr/WS/TCKimlikNoDogrula"',
'Content-Length: '.strlen($post_data)
),
);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
return (strip_tags($response) === 'true') ? true : false;
}
}