Results 1 to 4 of 4

Thread: 18+ years register control

  1. #1
    Join Date
    Aug 2009
    Posts
    398
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default 18+ years register control

    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:
    PHP Code:
    $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:
    HTML Code:
    <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.

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    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.

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    There's some already written here: http://www.dreamincode.net/forums/to...cation-script/
    Corrections to my coding/thoughts welcome.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •