xyn Posted February 19, 2007 Share Posted February 19, 2007 Hey, Basically i have been tryin to check the age of a user who is trying to register to my members but if they are not 13 or older, i set a cookie and they must follow COPPA accordingly... but the important thing is my code doesnt work. I know i'm doing it wrong, and i don't know how to do it correctly, so could anyone please help? my code $birth = date("d/m/Y", strtotime("now -13 Years")); $dob[] = $_POST['day']; $dob[] = $_POST['month']; $dob[] = $_POST['year']; $dateob = implode("/", $dob); if($dateob > $birth) { $value = "YES"; setcookie("RegisterBan", $value, time()+(1825*24*60*60)); } Link to comment https://forums.phpfreaks.com/topic/39154-solved-checking-the-age-from-dob-problems/ Share on other sites More sharing options...
onlyican Posted February 19, 2007 Share Posted February 19, 2007 This is my function to get someones age <?php function GetAge($dob) { $dob = explode("-",$dob); $year = $dob[0]; $month = $dob[1]; $day = $dob[2]; $year_to = date("Y"); $month_to = date("m"); $day_to = date("d"); $age_this_year = $year_to - $year; $age_minus_one = $age_this_year - 1; if ($month_to == $month) { if ($day_to >= $day) { $age = $age_this_year; }else{ $age = $age_minus_one; } }else{ if ($month_to > $month) { $age = $age_this_year; }else{ $age = $age_minus_one; } } return $age; } ?> so you can do something like <?php if(GetAge($UsersDOB) <= 13){ //set cookie } ?> Link to comment https://forums.phpfreaks.com/topic/39154-solved-checking-the-age-from-dob-problems/#findComment-188551 Share on other sites More sharing options...
xyn Posted February 19, 2007 Author Share Posted February 19, 2007 Yes, I'll learn your function to see how you get around the conversion, if that's ok? Thanks dude! Link to comment https://forums.phpfreaks.com/topic/39154-solved-checking-the-age-from-dob-problems/#findComment-188569 Share on other sites More sharing options...
onlyican Posted February 19, 2007 Share Posted February 19, 2007 use my function if you want. I would not post it if I did not want people to use it Link to comment https://forums.phpfreaks.com/topic/39154-solved-checking-the-age-from-dob-problems/#findComment-188586 Share on other sites More sharing options...
xyn Posted February 19, 2007 Author Share Posted February 19, 2007 I still have a problem! it outputs 1980 :S Link to comment https://forums.phpfreaks.com/topic/39154-solved-checking-the-age-from-dob-problems/#findComment-188605 Share on other sites More sharing options...
onlyican Posted February 19, 2007 Share Posted February 19, 2007 with this, $dob[] = $_POST['day']; $dob[] = $_POST['month']; $dob[] = $_POST['year']; $dateob = implode("/", $dob); I aint suprised <?php $Dob = $_POST["year"]."/".$_POST["month"]."/".$_POST["day"]; if(GetAge($Dob) < 13){ $value = "YES"; setcookie("RegisterBan", $value, time()+(1825*24*60*60)); } ?> Link to comment https://forums.phpfreaks.com/topic/39154-solved-checking-the-age-from-dob-problems/#findComment-188611 Share on other sites More sharing options...
xyn Posted February 19, 2007 Author Share Posted February 19, 2007 its fine your code is the American way YYYY-MM-DD all i had to do is rotate the dob array to DD-MM-YYYY thanks! Link to comment https://forums.phpfreaks.com/topic/39154-solved-checking-the-age-from-dob-problems/#findComment-188623 Share on other sites More sharing options...
onlyican Posted February 19, 2007 Share Posted February 19, 2007 YYYY MM DD is not the american way USA Way is MM-DD-YYYY Its actually DB way, as I store the DB in the MySQL Table, under DATE Format Link to comment https://forums.phpfreaks.com/topic/39154-solved-checking-the-age-from-dob-problems/#findComment-188627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.