How to securely transfer credit card information between pages in PHP

How do you securely transfer credit card information between pages in PHP? I am creating an e-commerce application and I would like for users to be tested as follows:

Enter information → Overview → Complete order

The problem is that I’m not sure how to transfer credit information safely when the user enters them, when I process it (at the “Complete the order” stage). I heard that using sessions is not secure even with encryption.

Any help would be appreciated!

+7
security php e-commerce credit-card
source share
6 answers

I wouldn’t keep anything. This is too much risk and probably not ethical.

Send a request to the payment gateway by sending the form via https and save the result of the transaction only.

You may only be wondering if the transaction was approved or rejected. Who cares what the number is?

+10
source share

Do not store credit card information in a session, do not store it in a database, do not store it in a file. Instead, write cc information back to the browse page using the html hidden inputs.

So, the program flow will work as follows:

  • The user sends billing and payment information to the server through the html form.
  • The server checks that this information is in the correct format (for example, a credit card has the appropriate number of digits, a billing address has been entered, etc.).
  • After verification, the server records all the information presented as input fields of a hidden form. This includes your billing address, shipping address, and credit card information.
  • The form on the overview page (with hidden input fields) has a button that says "End Order" / "Full Order". This report form publishes an order completion script.
  • The finalization script stores billing / delivery information in your database and sends the credit card information to your payment gateway.

The advantages of this method are twice:

  • You save the overhead and additional PCI compliance requirements that are required when storing credit information.
  • This method is within the security of the SSL protocol. The value, encrypted credit card information must be sent to your server anyway - this method still relies solely on the effectiveness of SSL, without introducing the complexity of the stored credit card data.

Another problem arises in this last question: when you browse a page, you double the number of times that encrypted credit card data is transmitted over the network. With this method, there are a minimum of 4 transfers: client to server, server to client, client to server (again), and then server to gateway. Without verification, there are at least 2 transfers: from client to server and from server to gateway. Is the convenience of the review page a risk of extra gear? This is a decision that you, as a web developer (and your client), can make.

+8
source share

Well, you must first use the HTTPS protocol to make sure the connection is encrypted.

After that, you can save the data in the super-global $_SESSION . Data is stored on your servers, so it is relatively safe.

You can make a similar technique into which you insert information into the Order database, where the key is a GUID or something else rather random and unique. Then, when the user proceeds to change / revise his order, you should have the order identifier stored in the GET part of the URL (or if you are paranoid, the cookie / session variable):

  https://example.com/order?orderID=akjgflkhaslasdfkjhalsdjkljahs 

For added security, you can also save the IP address in the order table and make sure that the IP address and order ID match.

+1
source share

One option is to use a payment profile service, such as Authorize.net Customer Information Manager (there are others). You save information about payments in the profile through your API, and then use the profile identifier when actually charging the card. This way you never store data on your servers.

+1
source share

Not my area of ​​expertise, but I think you want to keep it in the session, but also use a “sync token” (or what children call these days) to avoid CSRF attacks.

Of course, you want to use https (correctly), avoiding getting sensitive data into the URL and hidden fields, avoiding getting very important information into any answer in general, etc. etc.

0
source share

I think I have to agree. Storing credit card numbers is too much of a risk, and the consequences can be significantly removed.

The ideal way is to pass information to a third-party processor and simply use the result returned to format the script logic.

 if (transaction){ // code goes here } else{ // code goes here } 

Hope you get the point ... :)

0
source share

All Articles