Validation of age?

Reply

Join Date: Aug 2007
Posts: 189
Reputation: martin5211 is an unknown quantity at this point 
Solved Threads: 14
martin5211 martin5211 is offline Offline
Junior Poster

Re: Validation of age?

 
0
  #21
Apr 19th, 2009
I'm using mainly one check... subtracting 18 years to 2009 would be 1991, so any user should have a born date below 1991 to access www.example.com. That conditional isn't dynamic, to adjust the code would be:

  1. $min_year = date('Y', time());
  2. $min_year = $min_year - 18; // Change this (minimum age)
  3.  
  4. if($year < $min_year){
  5. ...

But, I prefer to use 19 years on the first condition, due to I want to make a more refined checking for users whose born date is near to the year limit. In that case, I use strtotime() to discount years and generate a timestamp, then I compare the user timestamp (date to seconds from 1970) with the subtracted timestamp obtained from today.

You cannot use only strtotime() to check age because only will work with a date above 1970. For that reason, two checks.

Also, if you want to adjust the minimal age, change the value inside strtotime()
Last edited by martin5211; Apr 19th, 2009 at 4:36 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 117
Reputation: genieuk is an unknown quantity at this point 
Solved Threads: 0
genieuk genieuk is offline Offline
Junior Poster

Re: Validation of age?

 
0
  #22
Apr 19th, 2009
thanks will try tomorrow when i got some time.

Regards
genieuk
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC