-
Notifications
You must be signed in to change notification settings - Fork 1
/
NationalIdentity.php
189 lines (167 loc) · 5.83 KB
/
NationalIdentity.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/**
* Turkish National Identity Finder
*
* This PHP class can verify your Turkish National Identity number using algorithm without
* holder name and password. Also, you can find your family members idendtity numbers
* using your National identity.
*
* Please use this code for your personal purpose and education.
*
* WARNING: DO NOT USE FOR BAD PURPOSES.
*
* @author Alimsah YILDIRIM <[email protected]>
* @version 1.0
* @filename NationalIdentity.php
* @created 13.10.2019
* @licence GNU General Public Licence V3
*
*
*/
class NationalIdentity
{
private $m_foundedIdentites = array();
public $name;
public $surname;
public $birthDate;
public $nationalIdentity;
/**
* Verifies your National identity using your name, surname and birth date.
*
* @return boolean
*
*/
public function verifyIdentity()
{
$client = new SoapClient('https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx?WSDL');
try
{
$result = $client->TCKimlikNoDogrula(
[
'TCKimlikNo' => $this->nationalIdentity,
'Ad' => $this->name,
'Soyad' => $this->surname,
'DogumYili' => $this->birthDate
]);
if ($result->TCKimlikNoDogrulaResult)
{
return true;
}
else
{
return false;
}
}
catch (Exception $e)
{
return false;
}
}
/**
* Checks given national identity is correct or not without holder name and surname
*
* @return boolean
*
*/
public function checkAlgorithm()
{
if (isset($this->nationalIdentity))
{
if (strlen($this->nationalIdentity) == 11)
{
# the first digit of the sum of the first 10 digits gives the 11th digit.
$summary = 0;
for ($i = 0; $i < strlen($this->nationalIdentity) - 1; $i++)
{
$summary += $this->nationalIdentity[$i];
}
$summary = ''.$summary;
$lastDigit = $this->nationalIdentity[strlen($this->nationalIdentity) - 1];
if ($lastDigit == $summary[1])
{
# Also, Digit 10 of the sum of 7 times the sum of digits 1, 3, 5, 7
# and 9 and 9 times the sum of digits 2, 4, 6 and 8
$summary = 0;
$odd = $this->nationalIdentity[0] + $this->nationalIdentity[2] + $this->nationalIdentity[4] + $this->nationalIdentity[6] + $this->nationalIdentity[8];
$even = $this->nationalIdentity[1] + $this->nationalIdentity[3] + $this->nationalIdentity[5] + $this->nationalIdentity[7];
$odd = $odd * 7;
$even = $even * 9;
$summary = $odd + $even;
$summary = ''.$summary;
$length = strlen($summary);
if ($this->nationalIdentity[9] == $summary[$length - 1])
{
# 1, 3, 5, 7 and 9 is the 11th digit of the 8th digit of the total.
$summary = 0;
$summary = $this->nationalIdentity[0] + $this->nationalIdentity[2] + $this->nationalIdentity[4] + $this->nationalIdentity[6] + $this->nationalIdentity[8];
$summary = $summary * 8;
$summary = ''.$summary;
if ($summary[strlen($summary) - 1] == $this->nationalIdentity[10])
{
return true;
}
else return false;
}
else return false;
}
else return false;
}
else return false;
}
else return false;
}
/**
* Finds other family members based on your national identity
*
* @param integer $repeat
*
* @return void
*
*/
public function findFamilyNationalIdentities($repeat = 20, $print = true)
{
$familyIndex[$repeat];
if (isset($this->nationalIdentity))
{
$identity = null;
for ($i = 0; $i < strlen($this->nationalIdentity) - 2; $i++)
{
$identity .= $this->nationalIdentity[$i];
}
$last = $identity;
for ($i = 0; $i < $repeat; $i++)
{
$familyIndex[$i] = $last + 29999;
$last = $familyIndex[$i];
$last = strval($last);
$l = $last;
# finding 10th digit
$a = intval($l[0]) + intval($l[2]) + intval($l[4]) + intval($l[6]) + intval($l[8]);
$a = $a * 7;
$b = $l[1] + $l[3] + $l[5] + $l[7];
$b = $b * 9;
$c = $a + $b;
$c = ''.$c;
# finding 11th digit.
$d = intval($l[0]) + intval($l[2]) + intval($l[4]) + intval($l[6]) + intval($l[8]);
$d = $d * 8;
$d = ''.$d;
array_push($this->m_foundedIdentites, $familyIndex[$i].$c[strlen($c) - 1].$d[strlen($d) - 1]);
if ($print)
{
echo '<p>'.$familyIndex[$i].$c[strlen($c) - 1].$d[strlen($d) - 1].'</p>';
}
}
}
}
/**
* Returns founded national identities
*
* @return array
*
*/
public function getFoundedNationalIdentities()
{
return $this->m_foundedIdentites;
}
}