Jump to content

Creating a Credit Card Validation Class With PHP


westminster86

Recommended Posts

You dont valadate a credit card unless you own a bank, or have the abilty off using the

banks gateway to valadate the users deatail....

 

the only method i no is to use preg_match to valadate the numbers are the numbers correct

number format from there card provider............

 

that why we all use paypal or another credit card gateway.........

 

Link to comment
Share on other sites

The thing is im not actually selling the products. Its a project im doing for my final year. I have products that a user can to the shopping cart and when he/she goes to checkout it asks for their credit card details. I just want to validate the the users input. Can i still do this with paypal?

Link to comment
Share on other sites

The thing is im not actually selling the products. Its a project im doing for my final year. I have products that a user can to the shopping cart and when he/she goes to checkout it asks for their credit card details. I just want to validate the the users input. Can i still do this with paypal?

 

Since it's for a project, like the last person said, just use regular expressions.  There's most likely no need to do more than ensure that the credit card info is in the right format.

Link to comment
Share on other sites

So you wouldnt suggest using an algorithm of some sort but to use the preg_match instead?

 

Yup, as it's the easiest way to do it.  Why go through all the trouble if you're not actually processing the card?  Unless specifically told to go the extra mile, just ensure that there's 16 digits for the card number.

Link to comment
Share on other sites

The regex is an algorithm. An algorithm is simply a set of instructions to follow to turn a problem into a solution.

 

I'm not sure what sort of algorithm you'd use beyond making sure the input appears valid anyways ;)

 

Good point.  Regular expressions are really just pattern matching algorithms with unique (funky?) syntax.  It's a powerful tool to deal with validating all kinds of input.

Link to comment
Share on other sites

One last thing. I know its not ideal to store the these sensitive details in a database, but for my project im going to have to. Before storing the details im going to encrypt them. Ive only ever used the crypt fucntion to encrypt password fields. Would it be suitable to use this function for the credit card details? Is there a better option, is MD5 more appropriate?

Link to comment
Share on other sites

The thing is im not actually selling the products. Its a project im doing for my final year. I have products that a user can to the shopping cart and when he/she goes to checkout it asks for their credit card details. I just want to validate the the users input. Can i still do this with paypal?

 

The mod10 method will be more than enough for this particular purpose. The actual validation can then be left to whatever mechanism is in place for communicating with the online store banking services.

 

There's heaps of php scripts doing credit card validation on the web. Just search google for "creadit card validation php" (124,000 results). You can take a good look at a few of them and learn other issues like lenght, initial digit(s) and even where the control digit may be.

 

EDIT: regarding your last question...

 

Let's get something straight here. You are playing with fire. You shouldn't store credit card information on the database. If you do, you must inform the users you are doing that and you better make sure you are complying with your country privacy and data storing (or whatever it is called) laws. You will be in a whole world of ... if you are not doing these two things. So, since this is just a project, how about not storing that data?

Link to comment
Share on other sites

  • 8 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.