Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Age Verification Script

Status
Not open for further replies.

Berns

IS-IT--Management
Apr 25, 2002
41
US
I need to develop a script that will direct users to one area if they are under 13 and to another if they are 13 or older.

I am barely a beginner when it comes to PHP, I found the following script online, can anyone provide some direction on how to modify and implement it? Thanks!
*********
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

?>

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


 
The user has to enter their birthdate, then they have to be directed to the appropriate place. COPPA/legal reasons...

Any help appreciated.
 
Here's something for you ...

$date=&quot;19-05-1978&quot;; // May 19th 1978
$age=(date(&quot;Y&quot;,time()-mktime(0,0,0,$date[1],$date[0],$date[2]))-1970); Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Sorry, forget an $date=explode(&quot;-&quot;,$date); Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
I'm sorry, but I'm not sure that I understand...
 
The right code is this:

suppose the user enter the birthdate in dd-mm-yyyy format. The code you need is the one below.

Code:
$date=&quot;19-05-1978&quot;; // May 19th 1978 you don't have to have this. Put the date in some format and work it with the explode.
$date=explode(&quot;-&quot;,$date); 
$age=(date(&quot;Y&quot;,time()-mktime(0,0,0,$date[1],$date[0],$date[2]))-1970);



Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 

made slight alteration so you use
if (pass_coppa_check(8, 5, 1971, 13))
{
hello elderly people
}
else
{
hi kiddies
}

function pass_coppa_check($day, $month, $year, $year_limit){

//check to see if we have a 2 digit year. If so convert it to standard 4 char format
if (strlen($year) == 2){$year = &quot;19&quot; . $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.
$difference = $today - $birthdate;
$age_date = getdate($difference);

// age_date is how old you are in secs + epoch 1/1/1970
$age_in_years = date(&quot;Y&quot;,$age_date ) - date(&quot;Y&quot;,0);

//error check to make sure the date's not in the future
if ($age_in_years < $year_limit)
{
return FALSE;
}
else
{
return TRUE;
}

}//end coppa_check

?>
 
Okay, sorry to make this so difficult, but as I said, I', completely new to this.

How do I implement this code? I appreciate your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top