note 11844 added to function.mktime.php

From: Date: Fri, 09 Mar 2001 13:05:44 +0000
Subject: note 11844 added to function.mktime.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-12108@lists.php.net to get a copy of this message
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."; } } http://www.php.net/manual/en/function.mktime.php

« previous php.notes (#12108) next »