Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php credit card validation

<?
/* Luhn algorithm number checker - (c) 2005-2008 shaman - www.planzero.org *
 * This code has been released into the public domain, however please      *
 * give credit to the original author where possible.                      */

function luhn_check($number) {

  // Strip any non-digits (useful for credit card numbers with spaces and hyphens)
  $number=preg_replace('/D/', '', $number);

  // Set the string length and parity
  $number_length=strlen($number);
  $parity=$number_length % 2;

  // Loop through each digit and do the maths
  $total=0;
  for ($i=0; $i<$number_length; $i++) {
    $digit=$number[$i];
    // Multiply alternate digits by two
    if ($i % 2 == $parity) {
      $digit*=2;
      // If the sum is two digits, add them together (in effect)
      if ($digit > 9) {
        $digit-=9;
      }
    }
    // Total up the digits
    $total+=$digit;
  }

  // If the total mod 10 equals 0, the number is valid
  return ($total % 10 == 0) ? TRUE : FALSE;

}
?>
Comment

php validate credit card expiration date

$expires =  date_format( DateTime::createFromFormat('ym', $cc_expiration),"ym");

$now =  date_format(new DateTime(),"ym");

if ($expires < $now) {
    return 'Expired!';
}
Comment

PREVIOUS NEXT
Code Example
Php :: php check if class exists 
Php :: laravel form put method 
Php :: how to get just the first row from a table in laravel 
Php :: php header redirect with parameters 
Php :: email configuration for gmail in laravel 
Php :: add css to gutenberg editor 
Php :: laravel create or update eloquesnt 
Php :: sort array php 
Php :: laravel server sent events 
Php :: php round up 
Php :: get post index wordpress 
Php :: wp get_posts return ids 
Php :: laravel add attribute to model 
Php :: You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file laravel 
Php :: laravel carbon set timezone 
Php :: how convert the date and time to integer in laravel 
Php :: install php 5.6 mac 
Php :: insert data using seeder in laravel 
Php :: search query in laravel 
Php :: how can we check in the table in comma separated values in laravel 
Php :: laravel eloquent select case when 
Php :: html special characters php 
Php :: componentes blade laravel attributes merge 
Php :: laravel without global scope 
Php :: display image from database in laravel 
Php :: is_unique in codeigniter form validation 
Php :: php rotate image 
Php :: wordpress theme widgets 
Php :: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted 
Php :: php postgresql 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =