[quote]
(premetto che la funzione e' inutile)


Quando ancora ero all'ABC con il php feci questo piccolo scrphpbbt, un emulazione del semplicissimo algoritmo mod10(),

Fu un traguardo fare questo scrphpbbt, anche se il codice e' molto basilare e confusionario[/quote]

[code]<?php

#######################

#Verifier Credit Card Number
#Author = Scr34M
#Email = Scr34M_php@hotmail.it

#Programma:
#Verifica se le carte di credito sono vere o false seguendo l'algoritmo mod10() o formula di Lunh

#######################

$card = "0000000000000000"; //Inserire qui il numero della carta di credito a 16 cifre

$lunghezza_stringa = strlen($card);

if (is_numeric($card)) {

if ($lunghezza_stringa == 16) {

for ($i = 1;$i <= 15;$i++) {

$card[$i];

}

$num1 = $card[0] * 2;
$num2 = $card[2] * 2;
$num3 = $card[4] * 2;
$num4 = $card[6] * 2;
$num5 = $card[8] * 2;
$num6 = $card[10] * 2;
$num7 = $card[12] * 2;
$num8 = $card[14] * 2;

$num9 = $card[1];
$num10 = $card[3];
$num11 = $card[5];
$num12 = $card[7];
$num13 = $card[9];
$num14 = $card[11];
$num15 = $card[13];
$num16 = $card[15];

$num_array = array($num1, $num2, $num3, $num4, $num5, $num6, $num7, $num8);



if ($num_array[0] > 9) {
$a_0 = substr($num_array[0],0,1);
$b_0 = substr($num_array[0],1);
$doppio_valore_0 = $a_0 + $b_0;
$num_array[0] = 1;
$calcolo_0 = 0;
} else {
$num_array[0] = $num_array[0];
$doppio_valore_0 = 0;
}
if ($doppio_valore_0 == 0){
$calcolo_0 = $doppio_valore_0 + $num_array[0];
}

if ($num_array[1] > 9) {
$a_1 = substr($num_array[1],0,1);
$b_1 = substr($num_array[1],1);
$doppio_valore_1 = $a_1 + $b_1;
$num_array[1] = 1;
$calcolo_1 = 0;
} else {
$num_array[1] = $num_array[1];
$doppio_valore_1 = 0;
}
if ($doppio_valore_1 == 0){
$calcolo_1 = $doppio_valore_1 + $num_array[1];
}

if ($num_array[2] > 9) {
$a_2 = substr($num_array[2],0,1);
$b_2 = substr($num_array[2],1);
$doppio_valore_2 = $a_2 + $b_2;
$num_array[2] = 1;
$calcolo_2 = 0;
}else {
$num_array[2] = $num_array[2];
$doppio_valore_2 = 0;
}
if ($doppio_valore_2 == 0){
$calcolo_2 = $doppio_valore_2 + $num_array[2];
}

if ($num_array[3] > 9) {
$a_3 = substr($num_array[3],0,1);
$b_3 = substr($num_array[3],1);
$doppio_valore_3 = $a_3 + $b_3;
$num_array[3] = 1;
$calcolo_3 = 0;
} else {
$num_array[3] = $num_array[3];
$doppio_valore_3 = 0;

}
if ($doppio_valore_3 == 0){
$calcolo_3 = $doppio_valore_3 + $num_array[3];
}

if ($num_array[4] > 9) {
$a_4 = substr($num_array[4],0,1);
$b_4 = substr($num_array[4],1);
$doppio_valore_4 = $a_4 + $b_4;
$num_array[4] = 1;
$calcolo_4 = 0;
}else {
$num_array[4] = $num_array[4];
$doppio_valore_4 = 0;

}
if ($doppio_valore_4 == 0){
$calcolo_4 = $doppio_valore_4 + $num_array[4];
}

if ($num_array[5] > 9) {
$a_5 = substr($num_array[5],0,1);
$b_5 = substr($num_array[5],1);
$doppio_valore_5 = $a_5 + $b_5;
$num_array[5] = 1;
$calcolo_5 = 0;
}else {
$num_array[5] = $num_array[5];
$doppio_valore_5 = 0;
}
if ($doppio_valore_5 == 0){
$calcolo_5 = $doppio_valore_5 + $num_array[5];
}

if ($num_array[6] > 9) {
$a_6 = substr($num_array[6],0,1);
$b_6 = substr($num_array[6],1);
$doppio_valore_6 = $a_6 + $b_6;
$num_array[6] = 1;
$calcolo_6 = 0;
}else {
$num_array[6] = $num_array[6];
$doppio_valore_6 = 0;
}
if ($doppio_valore_6 == 0){
$calcolo_6 = $doppio_valore_6 + $num_array[6];
}

if ($num_array[7] > 9) {
$a_7 = substr($num_array[7],0,1);
$b_7 = substr($num_array[7],1);
$doppio_valore_7 = $a_7 + $b_7;
$num_array[7] = 1;
$calcolo_7 = $doppio_valore_7;
} else {
$num_array[7] = $num_array[7];
$doppio_valore_7 = 0;
}
if ($doppio_valore_7 == 0){
$calcolo_7 = $doppio_valore_7 + $num_array[7];
}


if ($num_array[0] == 1) {
$num_array[0] = 0;
}
if ($num_array[1] == 1) {
$num_array[1] = 0;
}
if ($num_array[2] == 1) {
$num_array[2] = 0;
}
if ($num_array[3] == 1) {
$num_array[3] = 0;
}
if ($num_array[4] == 1) {
$num_array[4] = 0;
}
if ($num_array[5] == 1) {
$num_array[5] = 0;
}
if ($num_array[6] == 1) {
$num_array[6] = 0;
}
if ($num_array[7] == 1) {
$num_array[7] = 0;
}


$risultato_num_singoli = $num_array[0] + $num_array[1] + $num_array[2] + $num_array[3] + $num_array[4] + $num_array[5] + $num_array[6] + $num_array[7];

$risultato_num_doppi = $doppio_valore_0 + $doppio_valore_1 + $doppio_valore_2 + $doppio_valore_3 + $doppio_valore_4 + $doppio_valore_5 + $doppio_valore_6 + $doppio_valore_7;

$resto_num = $num9 + $num10 + $num11 + $num12 + $num13 + $num14 + $num15 + $num16;

$risultato_generale = $risultato_num_singoli + $resto_num + $risultato_num_doppi;

$verifica = $risultato_generale / 10;

if (is_float($verifica)) {

echo "Numero Carta di credito NON Valido";

}else {

echo "Numero Carta di credito Valido";

}

}else{

echo "Lunghezza stringa = ".$lunghezza_stringa."--Errore Il numero della carta di credito deve contenere 16 numeri ";

}

} else {

echo "Assicurarsi che non siano presenti Caratteri";
}

?>[/code][PHP]Verifier Credit Card Number
Source viewer