dadamssg Posted March 15, 2009 Share Posted March 15, 2009 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 More sharing options...
kittrellbj Posted March 15, 2009 Share Posted March 15, 2009 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."; } Link to comment https://forums.phpfreaks.com/topic/149467-check-if-older-than-certain-age/#findComment-784975 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.