Forum Moderators: coopster
Based on a PHP/MySQL Form Mailer tutorial, I've created a form to send info to a database as well as to two recipients. The form (which is run off our webhost's secure server) also contains a credit card number. In sending the confirmation emails with the POST data, I don't want to send the credit card numbers via unsecure email. So, I want to have the numbers appear as ****xxxxxxxxx1234 (all x's except last four numbers).
I've got a snippet for doing this, but I'm totally stumped as to how to incorporate that into the form. At this point I am not concerned about whether or not the numbers have hyphens, etc....I just want to understand how the snippet should be inserted, then I will expand upon the code for the other concerns(I'm taking baby steps to learn a little at a time and understand how everything interacts).
Pertinent parts:
<?php
// strip credit card numbers to only 4 digits
//the following line is the snippet I'm having trouble with
//I don't know what to do with it do make it work with the rest of the form procesing code
$ccNumber2=substr($ccNumber, 0, 4) . str_repeat('x', (strlen($ccNumber) - 8)) . substr($ccNumber, - 4);
// puts POST variables into variables we can use
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$company=$_POST['company'];
$street=$_POST['street'];
$city=$_POST['city'];
$state=$_POST['state'];
$zip=$_POST['zip'];
$email=$_POST['email'];
$phoneHome=$_POST['phoneHome'];
$phoneWork=$_POST['phoneWork'];
$domain=$_POST['domain'];
$ccNumber=$_POST['ccNumber']; // needed for inserting all the cc no's into the
database
$ccType=$_POST['ccType'];
$ccNumber2=$_POST['ccNumber2'];
$ccMonth=$_POST['ccMonth'];
$ccDay=$_POST['ccDay'];
$ccYear=$_POST['ccYear'];
$bill_firstName=$_POST['bill_firstName'];
$bill_lastName=$_POST['bill_lastName'];
$billStreet=$_POST['billStreet'];
$billCity=$_POST['billCity'];
$billState=$_POST['billState'];
$billZip=$_POST['billZip'];
$username=$_POST['username'];
$pass=$_POST['pass'];
$agreeTerms=$_POST['agreeTerms'];
// validation routine, cut for space
// info below is sent to me and to the person submitting the form
//--------------------------------------
$mailContent="---------------CONTACT\n"
."First Name: ".$firstName."\n"
."Last Name: ".$lastName."\n"
."Company: ".$company."\n"
."Street Address: ".$street."\n"
."City: ".$city."\n"
."State: ".$state."\n"
."Zip Code: ".$zip."\n"
."E-mail Address: ".$email."\n"
."Home Phone: ".$phoneHome."\n"
."Work Phone: ".$phoneWork."\n\n--------------DOMAIN\n"
."Domain Name: ".$domain."\n\n---------------CREDIT CARD INFO\n"
."Credit Card: ".$ccType."\n"
."Credit Card Number: ".$ccNumber2."\n" // trying to get only 4 digits
here
."Credit Card Expiration Month: ".$ccMonth."\n"
."Credit Card Expiration Day: ".$ccDay."\n"
."Credit Card Expiration Year: ".$ccYear."\n"
."Billing Information:\n"
."First Name: ".$bill_firstName."\n"
."Last Name: ".$bill_lastName."\n"
."Street Address: ".$billStreet."\n"
."City: ".$billCity."\n"
."State: ".$billState."\n"
."Zip Code: ".$billZip."\n\n---------------ACCOUNT INFORMATION\n"
."Username: ".$username."\n"
."Password: ".$pass."\n";
// end of Mail Content
When I send the form with the $ccNumber2... as shown above, it's just blank
after the colon.
Hopefully someone can please help me with this...
Thanks,
Kathy
$ccNumber2 = str_repeat('x', (strlen($ccNumber) - 4)) . substr($ccNumber,-4,4);
then when you use $ccNumber2 later on in the code it should ouput this
123456789123 as ********xx9123
<added>the posting software makes stars out of multiple x's obviously.
I put in the code you suggested and got the same results...nothing after the colon.
Hopefully I'm wording this question correctly, but is that line of code (yours and the original line)intended to be inserted as it's written now, or is it supposed to be a piece of something more, like a function? I had actually attempted to write it as a function when it didn't work earlier today, but I had no luck with that either.
$ccNumber2 = str_repeat("x", (strlen($ccNumber) - 4)) . substr($ccNumber,-4,4);
explained verbally it would be
assign to the variable ccNumber2 a number of x's equal to 4 less than the length of the value of the variable ccNumber. Then add the last 4 digits of the value of the variable ccNumber.
try just using echo to view the contents of your 2 variables
echo "<p>cc1: ",$ccNumber;
$ccNumber2 = str_repeat("x", (strlen($ccNumber) - 4)) . substr($ccNumber,-4,4);
echo "<p>cc2: ",$ccNumber2;
When I did the echo, the two credit card values did appear on the confirmation page...
But they don't appear in the confirmation emails that go to me and the person submitting the form.
I can't get it passed along to this section in $mailContents so that ****xxxxxxxx1234 shows up in the emails (posting does change some of the x's to *'s):
."Credit Card Number: ".$ccNumber2."\n" // trying to get only 4 digits
here
Is the problem because $ccNumber2 doesn't come from a POST on the application page (the application page is processed by this proc.php page, which emails the contents of the variables and also inserts them into a database)?
I deleted
$ccType=$_POST['ccType'];
$ccNumber2=$_POST['ccNumber2'];
altogether from below the
// puts POST variables into variables we can use
section, and then the form worked as I wanted it to, sending only the last four digits in the emails.
Instead of working with the huge form I had, I deleted all but the basics and using that as a test version, it was easier to troubleshoot.
Thanks,
Kathy