943,812 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2900
  • PHP RSS
You are currently viewing page 3 of this multi-page discussion thread; Jump to the first page
Apr 19th, 2009
0

Re: Validation of age?

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:

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 52
Solved Threads: 23
Posting Whiz in Training
martin5211 is offline Offline
271 posts
since Aug 2007
Apr 19th, 2009
0

Re: Validation of age?

thanks will try tomorrow when i got some time.

Regards
genieuk
Reputation Points: 10
Solved Threads: 0
Junior Poster
genieuk is offline Offline
149 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Return Car Make from MySQL database & have the make hyperlinked.
Next Thread in PHP Forum Timeline: css gallery hit counter?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC