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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.