在Codeigniter中验证信用卡的最佳方法是什么 - php

嗨,我正在使用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中是否有任何库或帮助程序。请帮忙.....................

参考方案

正如人们已经告诉您的那样,CodeIgniter是一个php框架,使用php进行编码,可以在php环境中使用,并使用..,php类和函数:)。

此外,链接到的文件是一个简单的功能。一种功能。你知道你能做什么?将该文件原样保存,将其命名为creditcard_helper.php,将其放在helpers文件夹中,打开它,然后将整个代码放入此代码段中(这很丑陋,但很有必要,因为每当您第二次加载该helper时,它都会给您否则返回错误):

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';
}

PHP-将日期插入日期时间字段 - php

我已在数据库中使用datetime字段存储日期,使用PHP将“今天的日期”插入该字段的正确方法是什么?干杯, 参考方案 我认为您可以使用php date()函数

php ziparchive类源代码 - php

Improve this question 我如何获取ziparchive类本身的源代码。 参考方案 假设您在谈论PHP ZipArchive class:下载PHP source code并查找适当的文件。如果您希望源代码是PHP代码,您可能会感到失望,因为源代码是用C语言编写的。或者,也可以在PHP Github Development Reposito…

PHP getallheaders替代 - php

我正在尝试从服务器上的apache切换到nginx。唯一的问题是我在PHP脚本中使用的getallheaders()函数,该函数不适用于Nginx。我已经尝试过用户在getallheaders函数上的php站点上提供的注释,但这并不返回所有请求标头。请告诉我如何解决这个问题。我真的想切换到Nginx。 参考方案 您仍然可以使用它,但是您必须像这里一样重新定义…

php:将分钟取整到最近的四分之一小时,然后执行更多操作 - php

最初的问题是这样的:取分钟数->转换为四分之一小时-> 1个四分之一小时为1个单位->输出单位我今天整天都在整理页面,几分钟前我的大脑就停止工作了,我只是不知道如何输出单位数量。我知道在此网站上发布问题会有所帮助。因此,用户输入的分钟数(不是小时和分钟,而是数分钟),站点需要输出单位数量。单位是一个刻钟。分钟总是四舍五入到最近的四分之一小时…

PHP mysqli获取查询返回的第一行的值 - php

我正在使用mysqli从数据库中获取某些数据。我正在使用的查询已设置为仅从数据库返回一行。有没有一种方法可以在不使用while循环的情况下获取该行的值?我知道一个while循环对于返回多于一行的行很有用,但是如果不需要while循环,我想避免这种情况,因为不必要的代码是不好的编程。 参考方案 是的-您可以使用:$row = $result->fetch…