PHP Classes

How to Implement PHP Credit Card Validation Using the Package Card Validator PHP: Validate different types of credit card numbers

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-03-06 (5 hours ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
cardvalidatorphp 1.0Custom (specified...5PHP 5, E-Commerce, Validation
Description 

Author

This package can validate different types of credit card numbers.

It provides a script that processes a credit card number passed as HTTP GET parameter value to check if it can be valid by checking the card digits.

Currently, it can validate credit cards of providers like VISA, MasterCard, Elo, Discover and Hypercard.

Picture of VITOR GABRIEL M. DANTAS
  Performance   Level  
Name: VITOR GABRIEL M. DANTAS <contact>
Classes: 2 packages by
Country: Brazil Brazil

Documentation

API de Identificação de Bandeira de Cartão de Crédito

Este projeto é uma pequena API desenvolvida em PHP que identifica a bandeira de cartões de crédito com base no número informado na URL.

Tecnologias Utilizadas

  • PHP 7 ou superior
  • JSON para retorno de dados

Como Funciona

A API recebe o número do cartão via parâmetro na URL e retorna um JSON informando a bandeira do cartão de crédito ou se a bandeira é desconhecida.

Regras de Identificação:

| Bandeira | Regra | | ---------------- | ---------------------------------------------------------------------------- | | Visa | Inicia com 4 | | Mastercard | Inicia entre 51-55 ou entre 2221-2720 | | Elo | Inicia com diversos prefixos como 4011, 4312, 4389, entre outros | | American Express | Inicia com 34 ou 37 | | Discover | Inicia com 6011, 65 ou entre 644-649 | | Hipercard | Inicia com 6062 |

Como Usar

  1. Suba o arquivo PHP em seu servidor.
  2. Acesse a API pela URL com o número do cartão como parâmetro.

Exemplo de Requisição:

http://seuservidor.com/cartao.php?numero_cartao=4111111111111111

Resposta:

{
  "numero_cartao": "4111111111111111",
  "bandeira": "Visa"
}

Tratamento de Erros

Caso o número do cartão não seja informado, a API retornará:

{
  "erro": "Número do cartão não informado"
}

Melhorias Futuras

  • Validação mais rigorosa para números de cartão inválidos.
  • Suporte a mais bandeiras.
  • Endpoint POST para maior segurança.

Credit Card Brand Identification API

This project is a small PHP API that identifies credit card brands based on the number provided in the URL.

Technologies Used

  • PHP 7 or higher
  • JSON for data response

How It Works

The API receives the card number via URL parameter and returns a JSON informing the credit card brand or if the brand is unknown.

Identification Rules:

| Brand | Rule | |----------------|-------------------------------------------------------| | Visa | Starts with 4 | | Mastercard | Starts between 51-55 or between 2221-2720 | | Elo | Starts with various prefixes like 4011, 4312, 4389, among others | | American Express | Starts with 34 or 37 | | Discover | Starts with 6011, 65 or between 644-649 | | Hipercard | Starts with 6062 |

How to Use

  1. Upload the PHP file to your server.
  2. Access the API via URL with the card number as a parameter.

Request Example:

http://yourserver.com/card.php?numero_cartao=4111111111111111

Response:

{
  "numero_cartao": "4111111111111111",
  "bandeira": "Visa"
}

Error Handling

If the card number is not provided, the API will return:

{
  "erro": "Card number not provided"
}

Future Improvements

  • Stricter validation for invalid card numbers.
  • Support for more brands.
  • POST endpoint for better security.


  Files folder image Files (11)  
File Role Description
Files folder imagevendor (1 file, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file index.php Appl. Configuration script
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (11)  /  vendor  
File Role Description
Files folder imagecomposer (7 files)
  Accessible without login Plain text file autoload.php Aux. Configuration script

  Files folder image Files (11)  /  vendor  /  composer  
File Role Description
  Accessible without login Plain text file autoload_classmap.php Aux. Configuration script
  Accessible without login Plain text file autoload_namespaces.php Aux. Configuration script
  Accessible without login Plain text file autoload_psr4.php Aux. Configuration script
  Plain text file autoload_real.php Class Class source
  Plain text file autoload_static.php Class Class source
  Plain text file ClassLoader.php Class Class source
  Accessible without login Plain text file LICENSE Lic. License text

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0