PHP code example of chrsc / luhn-algorithm

1. Go to this page and download the library: Download chrsc/luhn-algorithm library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

chrsc / luhn-algorithm example snippets



	$number = 123456;
	$luhn = new LuhnAlgorithm;
	if($luhn->validate($number)) {
		// number passes validation
	} else {
		// number does not pass validation
	}


	$luhn = new LuhnAlgorithm;
	$length = 16;
	$startswith = 4444;
	$cardnumber = $luhn->create($length, $startswith);
	// $cardnumber is now a valid card number that can be used or assigned