I use the script below to detect age so that user can not register if he/she is under 18. it works, but there is one problem - if user selects February 29 as birthdate he gets "You are too young" even if year is 1920....
Any ideas?
$birthdate = "$year-$month-$day";
$age = calc_age($birthdate);
if ($age < 18) {
die("You are too young");
}
function calc_age($birthdate){
$date_elements = explode("-" ,$birthdate);
if (!checkdate($date_elements[1],$date_elements[2],$date_elements[0])) return "";
$iMonth = $date_elements[1];
$iDay = $date_elements[2];
$iYear = $date_elements[0];
If ($iYear < 100) $iYear = 1900 + $iYear;
$baseyear = date("Y") - $iYear - 1;
If ($iMonth < date("m") OR ($iMonth == date("m") AND $iDay <= date("d"))) $baseyear++;
return $baseyear;
}
else{
return "";
}