Zend - The PHP Company




Miscellaneous

Add Code


coppa_check  

Type: code fragment
Added by: c0dem0nkey
Entered: 31/10/2001
Last modified: 01/11/2000
Rating: - (fewer than 3 votes)
Views: 3938
This is a down and dirty COPPA age verifier. This function takes 3 args. A birthday, a birthmonth and a birthyear and returns the users actual age if it's good and false if it's non-compliant. Throw this into a general include file and slap it in your library and you won't have to worry if you're letting any kids in. This is an important issue since it's illegal to gather user data if the person is under 13 years old.


<?
/***********************************************************************
Name: coppa_check($day, $month, $year)

Author: Jason DeFillippo <jason@mykungfu.com>

Description: This is a down and dirty COPPA age verifier. This function takes 3 args. A birthday, a birthmonth and a birthyear and returns the users actual age if it's good and false if it's non-compliant. Throw this into a general include file and slap it in your library and you won't have to worry if you're letting any kids in. This is an important issue since it's illegal to gather user data if the person is under 13 years old.
***********************************************************************/
function coppa_check($day$month$year){

    
//check to see if we have a 2 digit year. If so convert it to standard 4 char format
    
if (strlen($year) == 2){$year "19" $year;}    
    
    
//First do a check to see if we have a good date
    
$isgood checkdate($month$day$year);

    
//dump it if the date is bad...
    
if ($isgood != 1){
        return 
FALSE;
    }

    
//do some date to timestamp conversions
    
$birthdate mktime(0,0,0,$month,$day,$year);
    
$today time();
    
    
//now do them back so we can get some different info.
    
$old_date getdate($birthdate);
    
$current_date getdate($today);

    
//error check to make sure the date's not in the future
    
if ($current_date[year] < $year){return FALSE;}

    
//adjust for day of the month and get final age.
    
if ($current_date[yday] >= $old_date[yday]){
        
$age $current_date[year] - $year;
    }else{
        
$age = ($current_date[year] - $year) -1;
    }

    
//age range check
    
if ($age 13 || $age 120){
        return 
FALSE;
    }

    
//fallthru and spit back the actual age just for fun.
    
return $age;

}
//end coppa_check

?>


Usage Example


if ($age = coppa_check(8, 5, 1971)){ 
    echo "$age years old";
 }else{
     echo "Non-compliant age";
}


Rate This Script





Search



This Category All Categories