PHP: how to verify if the entered bank card is valid php, code, verification, bank card
How does PHP verify whether the entered bank card is valid? when I enter a bank card for a lost object, I want to verify whether the bank card is valid like an ID card, can verify whether the string matches, please find the complete code! I heard that there is a luhn algorithm, but this seems incomplete. Who will give me a function that can be used right away?
Reply to discussion (solution)
Online, etc ~~~~!! Please
The LUHN algorithm is mainly used to calculate the validity of credit card and other document numbers.
1. starting from the last digit of the card number, multiply the even digit by 2. if the result is two digits, add and save the two digits.
2. add all numbers to get the sum.
3. if the credit card number is valid, the sum can be divided by 10.
Therefore
function luhn($s) { $n = 0; for($i=strlen($s)-1; $i>=0; $i--) { if($i % 2) $n += $s{$i}; else { $t = $s{$i} * 2; if($t > 9) $t = $t{0} + $t{1}; $n += $t; } } return ($n % 10) == 0;}
The LUHN algorithm is mainly used to calculate the validity of credit card and other document numbers.
1. starting from the last digit of the card number, multiply the even digit by 2. if the result is two digits, add and save the two digits.
2. add all numbers to get the sum.
3. if the credit card number is valid, the sum can be divided by 10.
Therefore
function luhn($s) { $n = 0; for($i=strlen($s)-1; $i>=0; $i--) { if($i % 2) $n += $s{$i}; else { $t = $s{$i} * 2; if($t > 9) $t = $t{0} + $t{1}; $n += $t; } } return ($n % 10) == 0;}
Your code seems to have to check whether the credit card is correct? What about debit cards?
Then go to the algorithm description.
Then go to the algorithm description.
I just tested it. it seems that my credit card cannot be tested either. I cannot test a few cards.
No way. I found the algorithm description online.
If you say no, unless you give an algorithm description that you think is correct
Generally, the last four digits are verified.
The LUHN algorithm is mainly used to calculate the validity of credit card and other document numbers.
1. starting from the last digit of the card number, multiply the even digit by 2. if the result is two digits, add and save the two digits.
2. add all numbers to get the sum.
3. if the credit card number is valid, the sum can be divided by 10.
Therefore
function luhn($s) { $n = 0; for($i=strlen($s)-1; $i>=0; $i--) { if($i % 2) $n += $s{$i}; else { $t = $s{$i} * 2; if($t > 9) $t = $t{0} + $t{1}; $n += $t; } } return ($n % 10) == 0;}
Your code seems to have to check whether the credit card is correct? What about debit cards? Do I have to upload a name ?? Never touched
Php credit card number verification function
Http://3aj.cn/php/69.html