Forum Moderators: coopster

Message Too Old, No Replies

Form - User Age (>13) Verification Quick Question

         

kazisdaman3

2:31 am on Feb 28, 2007 (gmt 0)

10+ Year Member



Hi everyone!

Quick question couldn't find answer searching so I appreicate your time by reading this!

I want to check if user is 13 years old, or greater.

I take in:

<option value="1">January</option> for months
<option value="1">1</option> for days
<option value="2006">2006</option> for years.

How could I use, theses integers to work with the time() to check if they are 13 years or older?

Thank You,
Wesley

eelixduppy

2:41 am on Feb 28, 2007 (gmt 0)



This can be done using mktime [us2.php.net]. Try something like this:

$day = 10;
$month = 12;
$year = 1996;
$age_sec = mktime(0,0,0,$month,$day,$year);
$now = [url=http://us2.php.net/manual/en/function.time.php]time[/url](); #current time
$age = (($now-$age_sec)/31556926); #you divide here by the amount of seconds in one year
if(floor($age) < 13) {
echo 'You must be at least 13 to view this content!';
} else {
echo 'Welcome!';
}

Now you just have to use POST variables instead of the ones I have above.

Good luck! :)

Note:


Before PHP 5.1.0, negative timestamps were not supported under any known version of Windows and some other systems as well.

Therefore the above code really won't well with strange birth dates unless they fall within the range based on the system and version of php.

For a better solution, look at the last post [webmasterworld.com]

[edited by: eelixduppy at 5:45 pm (utc) on Mar. 10, 2007]

kazisdaman3

2:43 am on Feb 28, 2007 (gmt 0)

10+ Year Member



Thank you, eelixduppy!

I think thats the second time you helped me, I greatly appreciate it.

Wish you success, thanks!

henry0

12:26 pm on Feb 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As the devil advocate
I am wondering why you bother to find it?
I wildly guess you could not "LEGALLY" verify it.

So why not use a simple button such as "I am.." or "I am not .."
It’ll save coding time!
Or even simpler just state "You ought to be 13+ to access the following.
Now I would be very happy to know if you found any means to online age verification.
Please understand that my object is not to criticize your quest, but simply getting a broad understanding of your quest.

jatar_k

1:38 pm on Feb 28, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if that is DOB then you could also just straight check the year, if it wasn't more than 13 yrs ago then they can't really be over 13 ;)

eelixduppy

8:07 pm on Feb 28, 2007 (gmt 0)




if that is DOB then you could also just straight check the year

hehe...that is true, however, let's say someone was born october of 1988. 2007 - 1988 = 19, however they'd truly be 18. So you kind of have to take into account the month and day, unless you don't want to be that specific. ;)

coopster

3:59 pm on Mar 1, 2007 (gmt 0)