I created a check age function in PHP to make sure the user is at or over thirteen years old. And I don't understand why it isn't working. Please help. $varday = users brith day $varmonth = users brith month $varyear = users brith year //check age if ($showfail == 0 && $bdayerror == "") { //add zeros if less than 10 if ($varday < 10){ $varday = "0" . $varday; } if ($varmonth < 10){ $varmonth = "0" . $varmonth; } //get current day and append bday $currentdate = date("U"); $userbday = $varmonth . "//" . $varday . "//" . $varyear; //calculate bday in unix timestamp $userage = $currentdate - strtotime($userbday); //check if at or older than 13 if ($userage < (31556925*13)) { //set error message variable $bdayerror = "You are under thirteen years old and therefore are not old enough to access this site!"; $showfail = 1; } } Thanks. ~Imozeb
hi, try to replace this line: $userbday = $varmonth . "//" . $varday . "//" . $varyear; Code (markup): with this line: $userbday = $varmonth . "/" . $varday . "/" . $varyear; Code (markup):
<?php $varday = "12"; $varmonth = "2"; $varyear = "1996"; $currentdata = getdate(); $userbday = $varmonth . "/" . $varday . "/" . $varyear; $age = $currentdata['year'] - $varyear; if ($currentdata['mon'] < $varmonth) $age--; if ($currentdata['mon'] == $varmonth) if ($currentdata['mday'] < $varday) $age--; if ($age < 13) echo "[$age] You are under thirteen years old and therefore are not old enough to access this site!"; else echo "[$age] old enough"; ?> PHP: