Download the PHP package designbycode/luhn-algorithm without Composer

On this page you can find all versions of the php package designbycode/luhn-algorithm. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package luhn-algorithm

Luhn Algorithm

Latest Version on Packagist Tests Total Downloads

The Luhn Algorithm is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, and others. This documentation provides an overview of the Luhn Algorithm implementation in PHP, including examples and use cases.

Installation

You can install the package via composer:

Usage

Validating a Value

To validate a value using the Luhn Algorithm, create an instance of the LuhnAlgorithm class and call the isValid method:

The isValid method returns true if the value is valid, and false otherwise.

Generating a Check Digit

To generate a check digit for a given value, call the method:

The generate method returns the generated value including the check digit.

Stripping the Check Digit

To strip the check digit from a given value, call the withoutDigit method:

The withoutDigit method returns the value without the check digit.

Validating and Suggesting a Check Digit

To validate a value and suggest the correct check digit if invalid, call the validateAndSuggest method:

The validateAndSuggest method returns an array containing isValid and suggestedDigit values.

Use Cases

Credit Card Validation

The Luhn Algorithm is commonly used to validate credit card numbers. You can use the isValid method to check if a credit card number is valid:

IMEI Number Validation

The Luhn Algorithm can also be used to validate IMEI numbers. You can use the isValid method to check if an IMEI number is valid:

Generating Check Digits for IDs

You can use the generate method to generate check digits for various identification numbers, such as customer IDs or product codes:

Error Handling

The Luhn Algorithm implementation throws an InvalidArgumentException if the input value is empty or invalid. You can catch this exception to handle errors:

Conclusion

The Luhn Algorithm implementation in PHP provides a simple and efficient way to validate and generate check digits for various identification numbers. By following this documentation, you can easily integrate the Luhn Algorithm into your PHP applications.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of luhn-algorithm with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2|^8.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package designbycode/luhn-algorithm contains the following files

Loading the files please wait ....