| | |
Validation of age?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2007
Posts: 189
Reputation:
Solved Threads: 14
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:
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()
php Syntax (Toggle Plain Text)
$min_year = date('Y', time()); $min_year = $min_year - 18; // Change this (minimum age) if($year < $min_year){ ...
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.
![]() |
Similar Threads
- html/php form for .htaccess validation (PHP)
- error in javascrip form validation.. pls help (PHP)
- Help me in username and password validation through accessing the database (ASP.NET)
- Epected Primary Errors (C++)
- Problems with Switch (C++)
- Validation COntrol (C#)
- Age Calculator (C)
- Data validation (C++)
Other Threads in the PHP Forum
- Previous Thread: Return Car Make from MySQL database & have the make hyperlinked.
- Next Thread: css gallery hit counter?
| Thread Tools | Search this Thread |
advanced apache api array basics beginner binary broken cakephp check checkbox class cms code codingproblem combobox cookies cron curl database date datepart display dynamic echo email error file files folder form forms function functions google head href htaccess html image include includingmysecondfileinthechain insert ip javascript job joomla js limit link login mail menu mlm mobile multiple mysql nodes oop outofmemmory paging parse password paypal pdf php problem procedure query radio random recursion remote script search server sessions smarty sms source space sql stored syntax system table traffic tutorial unicode up-to-date update upload url validation validator variable video web webapplications youtube





