嗨,我使用codeigniter。 我想验证我的信用卡信息。 我看到在PHP中有类来验证信用卡号码。 我在codeigniter中看到一个助手来验证信用卡
http://codeigniter.com/wiki/Credit_Card_Helper
/** * Truncates a card number retaining only the first 4 and the last 4 digits. It then returns the truncated form. * * @param string The card number to truncate. * @return string The truncated card number. */ function truncate_card($card_num) { $padsize = (strlen($card_num) < 7 ? 0 : strlen($card_num) - 7); return substr($card_num, 0, 4) . str_repeat('X', $padsize). substr($card_num, -3); } /** * Validates a card expiry date. Finds the midnight on first day of the following * month and ensures that is greater than the current time (cards expire at the * end of the printed month). Assumes basic sanity checks have already been performed * on month/year (i.e. length, numeric, etc). * * @param integer The expiry month shown on the card. * @param integer The expiry year printed on the card. * @return boolean Returns true if the card is still valid, false if it has expired. */ function card_expiry_valid($month, $year) { $expiry_date = mktime(0, 0, 0, ($month + 1), 1, $year); return ($expiry_date > time()); } /** * Strips all non-numerics from the card number. * * @param string The card number to clean up. * @return string The stripped down card number. */ function card_number_clean($number) { return ereg_replace("[^0-9]", "", $number); } /** * Uses the Luhn algorithm (aka Mod10) <http://en.wikipedia.org/wiki/Luhn_algorithm> * to perform basic validation of a credit card number. * * @param string The card number to validate. * @return boolean True if valid according to the Luhn algorith, false otherwise. */ function card_number_valid ($card_number) { $card_number = strrev(card_number_clean($card_number)); $sum = 0; for ($i = 0; $i < strlen($card_number); $i++) { $digit = substr($card_number, $i, 1); // Double every second digit if ($i % 2 == 1) { $digit *= 2; } // Add digits of 2-digit numbers together if ($digit > 9) { $digit = ($digit % 10) + floor($digit / 10); } $sum += $digit; } // If the total has no remainder it's OK return ($sum % 10 == 0); } ?>它使用了一个通用的验证。 但我想要根据卡片类型进行验证
http://www.braemoor.co.uk/software/creditcard.php
codeigniter中是否有任何库或帮助程序? 请帮忙.....................
hi i am using codeigniter . i want to validate my credit card details . i saw there are classes in php to validate credit card numbers . i saw a helper in codeigniter to validate credit cards
http://codeigniter.com/wiki/Credit_Card_Helper
/** * Truncates a card number retaining only the first 4 and the last 4 digits. It then returns the truncated form. * * @param string The card number to truncate. * @return string The truncated card number. */ function truncate_card($card_num) { $padsize = (strlen($card_num) < 7 ? 0 : strlen($card_num) - 7); return substr($card_num, 0, 4) . str_repeat('X', $padsize). substr($card_num, -3); } /** * Validates a card expiry date. Finds the midnight on first day of the following * month and ensures that is greater than the current time (cards expire at the * end of the printed month). Assumes basic sanity checks have already been performed * on month/year (i.e. length, numeric, etc). * * @param integer The expiry month shown on the card. * @param integer The expiry year printed on the card. * @return boolean Returns true if the card is still valid, false if it has expired. */ function card_expiry_valid($month, $year) { $expiry_date = mktime(0, 0, 0, ($month + 1), 1, $year); return ($expiry_date > time()); } /** * Strips all non-numerics from the card number. * * @param string The card number to clean up. * @return string The stripped down card number. */ function card_number_clean($number) { return ereg_replace("[^0-9]", "", $number); } /** * Uses the Luhn algorithm (aka Mod10) <http://en.wikipedia.org/wiki/Luhn_algorithm> * to perform basic validation of a credit card number. * * @param string The card number to validate. * @return boolean True if valid according to the Luhn algorith, false otherwise. */ function card_number_valid ($card_number) { $card_number = strrev(card_number_clean($card_number)); $sum = 0; for ($i = 0; $i < strlen($card_number); $i++) { $digit = substr($card_number, $i, 1); // Double every second digit if ($i % 2 == 1) { $digit *= 2; } // Add digits of 2-digit numbers together if ($digit > 9) { $digit = ($digit % 10) + floor($digit / 10); } $sum += $digit; } // If the total has no remainder it's OK return ($sum % 10 == 0); } ?>it uses a common validation . but i want a validation according to card type like this
http://www.braemoor.co.uk/software/creditcard.php
is there any libraries or helpers in codeigniter . please help.....................
最满意答案
正如人们已经告诉你的,CodeIgniter是一个php框架,使用php编码,在php环境中工作,并使用..,php类和函数:)。
更重要的是,你链接的文件是一个简单的功能。 一个功能。 你知道你可以做什么? 按照原样取出文件,将其命名为creditcard_helper.php ,将其放入helpers文件夹中,将其打开并将整个代码放入此代码段中(丑陋但必要,因为每当您第二次加载帮助程序时它都会给您错误,否则):
if(!function_exists('checkCreditCard') { //the whole content goes here untouched; }你就定了。 只需使用:
$this->load->helper('creditcard'); if(checkCreditCard($cardnumber, $cardname, &$errornumber, &$errortext)) { echo 'card OK'; } else { echo 'wrong card type/number'; }As people already told you, CodeIgniter is a php framework, coded using php, works in a php environment and makes use of..,php classes and functions :).
What's more, the file you linked to is a simple function. One function. You know what you can do? Take the file as it is, name it creditcard_helper.php, put it inside the helpers folder, open it and place the whole code inside this snippet (ugly but necessary, as whenever you'll load the helper a second time it would give you error otherwise):
if(!function_exists('checkCreditCard') { //the whole content goes here untouched; }And you're set. Just use:
$this->load->helper('creditcard'); if(checkCreditCard($cardnumber, $cardname, &$errornumber, &$errortext)) { echo 'card OK'; } else { echo 'wrong card type/number'; }在codeigniter中验证信用卡的最佳方式是什么?(What is the best way to validate a credit card in codeigniter)嗨,我使用codeigniter。 我想验证我的信用卡信息。 我看到在PHP中有类来验证信用卡号码。 我在codeigniter中看到一个助手来验证信用卡
http://codeigniter.com/wiki/Credit_Card_Helper
/** * Truncates a card number retaining only the first 4 and the last 4 digits. It then returns the truncated form. * * @param string The card number to truncate. * @return string The truncated card number. */ function truncate_card($card_num) { $padsize = (strlen($card_num) < 7 ? 0 : strlen($card_num) - 7); return substr($card_num, 0, 4) . str_repeat('X', $padsize). substr($card_num, -3); } /** * Validates a card expiry date. Finds the midnight on first day of the following * month and ensures that is greater than the current time (cards expire at the * end of the printed month). Assumes basic sanity checks have already been performed * on month/year (i.e. length, numeric, etc). * * @param integer The expiry month shown on the card. * @param integer The expiry year printed on the card. * @return boolean Returns true if the card is still valid, false if it has expired. */ function card_expiry_valid($month, $year) { $expiry_date = mktime(0, 0, 0, ($month + 1), 1, $year); return ($expiry_date > time()); } /** * Strips all non-numerics from the card number. * * @param string The card number to clean up. * @return string The stripped down card number. */ function card_number_clean($number) { return ereg_replace("[^0-9]", "", $number); } /** * Uses the Luhn algorithm (aka Mod10) <http://en.wikipedia.org/wiki/Luhn_algorithm> * to perform basic validation of a credit card number. * * @param string The card number to validate. * @return boolean True if valid according to the Luhn algorith, false otherwise. */ function card_number_valid ($card_number) { $card_number = strrev(card_number_clean($card_number)); $sum = 0; for ($i = 0; $i < strlen($card_number); $i++) { $digit = substr($card_number, $i, 1); // Double every second digit if ($i % 2 == 1) { $digit *= 2; } // Add digits of 2-digit numbers together if ($digit > 9) { $digit = ($digit % 10) + floor($digit / 10); } $sum += $digit; } // If the total has no remainder it's OK return ($sum % 10 == 0); } ?>它使用了一个通用的验证。 但我想要根据卡片类型进行验证
http://www.braemoor.co.uk/software/creditcard.php
codeigniter中是否有任何库或帮助程序? 请帮忙.....................
hi i am using codeigniter . i want to validate my credit card details . i saw there are classes in php to validate credit card numbers . i saw a helper in codeigniter to validate credit cards
http://codeigniter.com/wiki/Credit_Card_Helper
/** * Truncates a card number retaining only the first 4 and the last 4 digits. It then returns the truncated form. * * @param string The card number to truncate. * @return string The truncated card number. */ function truncate_card($card_num) { $padsize = (strlen($card_num) < 7 ? 0 : strlen($card_num) - 7); return substr($card_num, 0, 4) . str_repeat('X', $padsize). substr($card_num, -3); } /** * Validates a card expiry date. Finds the midnight on first day of the following * month and ensures that is greater than the current time (cards expire at the * end of the printed month). Assumes basic sanity checks have already been performed * on month/year (i.e. length, numeric, etc). * * @param integer The expiry month shown on the card. * @param integer The expiry year printed on the card. * @return boolean Returns true if the card is still valid, false if it has expired. */ function card_expiry_valid($month, $year) { $expiry_date = mktime(0, 0, 0, ($month + 1), 1, $year); return ($expiry_date > time()); } /** * Strips all non-numerics from the card number. * * @param string The card number to clean up. * @return string The stripped down card number. */ function card_number_clean($number) { return ereg_replace("[^0-9]", "", $number); } /** * Uses the Luhn algorithm (aka Mod10) <http://en.wikipedia.org/wiki/Luhn_algorithm> * to perform basic validation of a credit card number. * * @param string The card number to validate. * @return boolean True if valid according to the Luhn algorith, false otherwise. */ function card_number_valid ($card_number) { $card_number = strrev(card_number_clean($card_number)); $sum = 0; for ($i = 0; $i < strlen($card_number); $i++) { $digit = substr($card_number, $i, 1); // Double every second digit if ($i % 2 == 1) { $digit *= 2; } // Add digits of 2-digit numbers together if ($digit > 9) { $digit = ($digit % 10) + floor($digit / 10); } $sum += $digit; } // If the total has no remainder it's OK return ($sum % 10 == 0); } ?>it uses a common validation . but i want a validation according to card type like this
http://www.braemoor.co.uk/software/creditcard.php
is there any libraries or helpers in codeigniter . please help.....................
最满意答案
正如人们已经告诉你的,CodeIgniter是一个php框架,使用php编码,在php环境中工作,并使用..,php类和函数:)。
更重要的是,你链接的文件是一个简单的功能。 一个功能。 你知道你可以做什么? 按照原样取出文件,将其命名为creditcard_helper.php ,将其放入helpers文件夹中,将其打开并将整个代码放入此代码段中(丑陋但必要,因为每当您第二次加载帮助程序时它都会给您错误,否则):
if(!function_exists('checkCreditCard') { //the whole content goes here untouched; }你就定了。 只需使用:
$this->load->helper('creditcard'); if(checkCreditCard($cardnumber, $cardname, &$errornumber, &$errortext)) { echo 'card OK'; } else { echo 'wrong card type/number'; }As people already told you, CodeIgniter is a php framework, coded using php, works in a php environment and makes use of..,php classes and functions :).
What's more, the file you linked to is a simple function. One function. You know what you can do? Take the file as it is, name it creditcard_helper.php, put it inside the helpers folder, open it and place the whole code inside this snippet (ugly but necessary, as whenever you'll load the helper a second time it would give you error otherwise):
if(!function_exists('checkCreditCard') { //the whole content goes here untouched; }And you're set. Just use:
$this->load->helper('creditcard'); if(checkCreditCard($cardnumber, $cardname, &$errornumber, &$errortext)) { echo 'card OK'; } else { echo 'wrong card type/number'; }
发布评论