Log in

View Full Version : 18+ years register control



auriaks
06-04-2011, 12:20 PM
Hi,

I tried to create a register page, but faced a problem with age of users.

Thing is that I want to allow only 18+ years old users to register, but I cannot create a input which could count how many years they have by their input.

What I have tried was something like this:


$get_year = $_GET['year'];
$get_month = $_GET['month'];
$get_day = $_GET['day'];

if ($get_year > 1992 || $get_year < 1932) { $error = "denied"; $err7 = "Enter the birth year";}
elseif ($get_month > 12 || $get_month < 1) { $error = "denied"; $err7 = "Enter the birth month";}
elseif ($get_day > 31 || $get_day < 1) { $error = "denied"; $err7 = "Enter the birth day";}

$y_days = (2011 - $get_year)* 365;
$m_days = $get_month * 30;
$total_days = $y_days + $m_days + $get_day;
if ($total_days < 6600) { $error = "denied"; $err7 = "You must be over 18 to register";}
}


!!! but as you can see, it does not do all I want... I used 365 days a year, when we have 366 days every 4 years.
What is more I use 30 days a month, when we have 28, 30 and 31.
So all those errors can allow users to register when they are still 17.

What I can do to create such script, which would count the exact age.

My html script is:


<div id='td'>Your Birth Date</div>
<div id='td'>
<input class='small_inputas' MAXLENGTH=4 type="text" id='year'>
<input class='small_inputas' MAXLENGTH=2 type="text" id='month'>
<input class='small_inputas' MAXLENGTH=2 type="text" id='day'>
<div id="date2"></div>
</div>

So it actually only collects the numbers... I would like to have 3 inputs which could show where to write year, month and day.

As an example would Paypal.com website register page.

All suggestions are welcome... Thanks.

fastsol1
06-04-2011, 01:13 PM
It would be better to use use the strtotime () to check it. You would let them select their date as normal and then check it with the strtotime() and see if today is at least 18 years greater than their date.

bluewalrus
06-04-2011, 02:43 PM
There's some already written here: http://www.dreamincode.net/forums/topic/186871-age-verification-script/

djr33
06-04-2011, 03:59 PM
Correct. As the users above have suggested, don't try to do the math yourself. Convert it to a timestamp. (Actually, one complication with this is that if you have users over 40 years old, that's before 1970, but I think the system probably has some way to deal with that... I hope.)

1. Convert the manually input date of birth into a timestamp.
2. Do any math required on that timestamp.
3. Do anything you need to display or check after that. For example, the number of years is just a multiple of the number of seconds. Etc. Or you could display the new timestamp as a newly formatted date.

It's much easier to work with that format and there are functions that exist for it.


Note that of course there's no reliable way to know that they actually are 18 years old. The birthdate they entered may be incorrect. For example, on MTV.com there is a check to be sure that on some videos users are at least 18 years old to see them. But if you enter any date over 18 years old it works. So while I am actually over 18 years old, I don't take the time to enter my real birthdate-- just whatever numbers are easiest to click in the dropdowns that will let me see it. This will be the same on your site.

Of course that may not really be a problem-- you've done your legal job of requiring them to be that old. But if it's actually completely necessary, then you may need to confirm it using some other method such as a (very minimal, perhaps refunded) credit card payment. But that gets annoying and will make a lot of users not bother.