Article

Creating a Credit Card Validation Class With PHP

Page: 1 2 3 4 5 6 7

Here are two screen shots from my browser. The first one shows the HTML form, and the second shows the output once the form is submitted:

728_image1
Entering the card details

728_image2
The results of the card validation

Conclusion

In this article we've seen how we can take advantage of PHP's object oriented features (most notably classes) to create a credit card storage and validation class. We went through the components of this class in detail, and we finished off by creating a test script in which we instantiated our CCreditCard class and validated a sample card number.

If you're thinking of setting up an eCommerce site that will process/store visitors' credit card details, then you should take the class we've just made and customize it to suit your needs. You might want to add other functions to it to compare CCreditCard objects, format the card's details into an XML string, encrypt the card's details to a database, or even process the payment in real time.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links

Rate This Article

  • 1
    Poor
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
    Great

Comment on This Article

Have something to say?

Post A Comment

You need to be a member of the SitePoint Forums to comment on this post. Sign Up

Already a member? Post using your SitePoint Forums account: