使用Codeigniter进行信用卡验证
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Codeigniter进行信用卡验证相关的知识,希望对你有一定的参考价值。
Validate the credit card number and cvv code
class cc_validation { public function validateCreditcard_number($cc_num) { $credit_card_number = $this->sanitize($cc_num); // Get the first digit // Make sure it is the correct amount of digits. Account for dashes being present. switch ($firstnumber) { case 3: $data['card_type'] ="American Express"; { //return 'This is not a valid American Express card number'; $data['status']='false'; return $data; } break; case 4: $data['card_type'] ="Visa"; { //return 'This is not a valid Visa card number'; $data['status']='false'; return $data; } break; case 5: $data['card_type'] ="MasterCard"; { //return 'This is not a valid MasterCard card number'; $data['status']='false'; return $data; } break; case 6: $data['card_type'] ="Discover"; { //return 'This is not a valid Discover card number'; $data['status']='false'; return $data; } break; default: //return 'This is not a valid credit card number'; $data['card_type'] ="Invalid"; $data['status']='false'; return $data; } // Here's where we use the Luhn Algorithm $sum = 0; for ($i = 0; $i <= $last; $i++) { $sum += $map[$credit_card_number[$last - $i] + ($i & 1) * 10]; } if ($sum % 10 != 0) { //return 'This is not a valid credit card number'; $data['status']='false'; return $data; } // If we made it this far the credit card number is in a valid format $data['status']='true'; return $data; } public function validateCreditCardExpirationDate($mon,$yr) { $month = $this->sanitize($mon); $year = $this->sanitize($yr); { return 'false'; // The month isn't a one or two digit number } { return 'false'; // The year isn't four digits long } { return 'false'; // The card is already expired } { return 'false'; // The card is already expired } return 'true'; } public function validateCVV($cc_num, $cc_cvv) { $cardNumber = $this->sanitize($cc_num); $cvv = $this->sanitize($cc_cvv); // Get the first number of the credit card so we know how many digits to look for if ($firstnumber === 3) { { // The credit card is an American Express card but does not have a four digit CVV code return 'false'; } } { // The credit card is a Visa, MasterCard, or Discover Card card but does not have a three digit CVV code return 'false'; } return 'true'; } function sanitize($value) { } } /* End of file My_payment.php */ /* Location: ./system/application/libraries/My_payment.php */
以上是关于使用Codeigniter进行信用卡验证的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Codeigniter 在贝宝实时集成中启用信用卡/借记卡选项?