Jump to content

check if older than certain age


dadamssg

Recommended Posts

im tryin to write a section of script that checks if the user is at least thirteen years old. heres what i got, but it aint workin, it doesnt output any error

 

//make date values integars 

  $bmonth = intval($_POST['bmonth']);
  $bday = intval($_POST['bday']);
  $byear = intval($_POST['byear']);
  
$today = gmmktime(0,0,0,date('n'),date('j'),date('Y')); 
  $userbday = strtotime($bmonth, $bday, $byear);
  
  $difference = $today - $userbday;
  $thirteen = intval(12299040000);

   if($difference <= $thirteen)
       	{
    $messages[]= "You must be at least 13 years of age to register.";
    }

 

that big number is thirteen years old in seconds....i hope

Link to comment
https://forums.phpfreaks.com/topic/149467-check-if-older-than-certain-age/
Share on other sites

Found this link, might be helpful:

 

http://trevordavis.net/blog/tutorial/get-age-function/

 

Basically, to call the function in your script and check against age 13, it would be:

 

$user_age = age($month, $day, $year); //call the variables from form or wherever
if ($user_age <= 13) {
echo "You are too young to be here!"; }
   else { echo "You can get into the bar."; }

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.