Jump to content

[SOLVED] Checking the age from DOB (problems)


xyn

Recommended Posts

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));
}

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
}
?>

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));
}
?>

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.