Created
October 31, 2013 08:15
-
-
Save kdrdmr/7245937 to your computer and use it in GitHub Desktop.
Vergi kimlik no doğrulama
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function vergiKimlikDogrulama($vkno) { | |
$vkno = preg_replace('/\D/ui','',$vkno); | |
if (strlen($vkno) == 10) { | |
$vkno_array = str_split(strval($vkno)); | |
$v1 = (intval($vkno_array[0]) + 9) % 10; | |
$v2 = (intval($vkno_array[1]) + 8) % 10; | |
$v3 = (intval($vkno_array[2]) + 7) % 10; | |
$v4 = (intval($vkno_array[3]) + 6) % 10; | |
$v5 = (intval($vkno_array[4]) + 5) % 10; | |
$v6 = (intval($vkno_array[5]) + 4) % 10; | |
$v7 = (intval($vkno_array[6]) + 3) % 10; | |
$v8 = (intval($vkno_array[7]) + 2) % 10; | |
$v9 = (intval($vkno_array[8]) + 1) % 10; | |
$v_last_digit = intval($vkno_array[9]); | |
$v11 = ($v1 * 512) % 9; | |
$v22 = ($v2 * 256) % 9; | |
$v33 = ($v3 * 128) % 9; | |
$v44 = ($v4 * 64) % 9; | |
$v55 = ($v5 * 32) % 9; | |
$v66 = ($v6 * 16) % 9; | |
$v77 = ($v7 * 8) % 9; | |
$v88 = ($v8 * 4) % 9; | |
$v99 = ($v9 * 2) % 9; | |
if ($v1 != 0 && $v11 == 0) $v11 = 9; | |
if ($v2 != 0 && $v22 == 0) $v22 = 9; | |
if ($v3 != 0 && $v33 == 0) $v33 = 9; | |
if ($v4 != 0 && $v44 == 0) $v44 = 9; | |
if ($v5 != 0 && $v55 == 0) $v55 = 9; | |
if ($v6 != 0 && $v66 == 0) $v66 = 9; | |
if ($v7 != 0 && $v77 == 0) $v77 = 9; | |
if ($v8 != 0 && $v88 == 0) $v88 = 9; | |
if ($v9 != 0 && $v99 == 0) $v99 = 9; | |
$toplam = $v11 + $v22 + $v33 + $v44 + $v55 + $v66 + $v77 + $v88 + $v99; | |
if ($toplam % 10 == 0) { | |
$toplam = 0; | |
} else { | |
$toplam = (10 - ($toplam % 10)); | |
} | |
if ($toplam == $v_last_digit) { | |
return true; | |
} else { | |
return false; | |
} | |
} else{ | |
return false; | |
} | |
} | |
$valid_samples = array( | |
'0540033975', '0540033887', '0680066825', '1670068615', '3950079269', '3950079068', '4540017830', '4540017847', | |
'4780040920', '4870003769', '4870003751', '6300043009', '6300042985', '7360014117', '7360014109', '7400016053', | |
'7400016254', '7460064345', '7460064353', '7710018651', '8360031658', '8360031754', '8450027618', '8450027675', | |
'9130005852', '9130005878', | |
); | |
$invalid_samples = array('4780040913', '7700040832', '7700040828', '7710018660', '0680066806', '1670068624',); | |
echo "<pre>"; | |
echo "valid number test: <br>"; | |
foreach($valid_samples as $vkno){ | |
$check = vergiKimlikDogrulama($vkno); | |
echo "number: ".$vkno." test result: ".var_export($check,1)."<br>"; | |
} | |
echo "<br>invalid number test: <br>"; | |
foreach($invalid_samples as $vkno){ | |
$check = vergiKimlikDogrulama($vkno); | |
echo "number: ".$vkno." test result: ".var_export($check,1)."<br>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment