PHP Example: Scrub Credit Card Numbers For Security Purposes When Storing In Your Database.

By Xeon Xai  

Processing credit card orders online and storing them can be dangerous, not just for the customers, but also for your own reputation. With the sample code I’ve written for you from my own recent programming tasks, you will see how to take the incoming credit card number and scrub it clean so that only the last 4 digits will be shown when stored in your database.

Example credit card number:
4111111111111111 (Sample VISA number)

// Get length of credit card numbers (Usually 15 or 16 digits).
$scrub_length	= strlen($_POST['cc_number']);
// Find last four digits.
$scrub_last_4	= substr($_POST['cc_number'], $scrub_length-4, 4);
// Pad all numbers with an * except for the last 4 digits.
$scrub_pad	= str_pad($scrub_last_4, $scrub_length, "*", STR_PAD_LEFT);
// New scrubbed credit card number is the padded string.
$scrub_cc_number = $scrub_pad;

This is the final string that will be output:
************1111

Now insert the scrubbed credit card number into your database without worries of it being stolen and used by malicious intruders.

@mysql_query("INSERT  INTO `payments` (`cc_number`) VALUES('".$scrub_cc_number."')");

It’s fairly easy, not much to it.

Enjoy,

- Xeon

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

One Comment

  1. Posted October 27, 2008 at 2:39 PM | Permalink | Reply

    You write very well.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

Post a Comment

Your email is never shared. Required fields are marked *

*
*