PHP – Age Validation

The given PHP example returns true if the required age is less than the given date.

Code Example:
function ageLimit( $date, $reqAge ) {
    $date = strtotime( $date );
	if( $date !== false && $date !== -1 ) { // strtotime returns -1 < PHP 5.1.0         echo $diff = time() - $date;         return ( $diff / 31556926 > $reqAge ); // 31556926 seconds in a year
    }
    return false;
}

$req_age = ageLimit($date="26 March 1980", $age=25);
if($req_age){
	echo 'Age Limit Exceeded';
}
?>

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

One Response to PHP – Age Validation

  1. avatar
    Ash on April 27, 2011 at 12:56 pm

    well, I need to give it a test.

Leave a Reply

Your email address will not be published. Required fields are marked *

*