note 11844 deleted from function.mktime by vincent
| From: | vincent@php.net | Date: | Thu, 11 Sep 2003 20:33:06 +0000 |
| Subject: | note 11844 deleted from function.mktime by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-56246@lists.php.net to get a copy of this message | ||
Note Submitter: jnaspam@retina.net
----
I looked everywhere for this and couldn't find it, so here it is.
<P>
This is how to validate a credit card expiry date, if you already have it in the form
$month="mm" and $year="yyyy":
<P>
(note that my form has select boxes, which use the '-' value to indicate they haven't
been changed. you can remove this if you want)
<P>
// First you need this function...
function daysInMonth($month,$year) {
print "$month/$year";
for($thisDay=1;checkdate($month,$thisDay,$year);$thisDay++);
return $thisDay-1;
}
And then you need this:
if (($month == "-") || ($year == "-"))
{
$error_string=$error_string."<LI>Credit Card Expiration date is invalid.";
} else {
$day = daysInMonth($month,$year);
$now = time();
$exp=mktime(23,59,59,$month,$day,$year);
if ($now > $exp) {
$error_string=$error_string . "<LI> Credit card is expired.";
}
}