Friday, 13 September 2013

Age Verification PHP

Age Verification PHP

I'm using a script that works wonderfully to verify age for a website I'm
working on. Currently it's using a dropdown menu to select the Month, Day,
Year. I was hoping it was possible to change the dropdown to have the user
input the Month, Day, Year instead.
Here is the code:
<?php
define('MIN_AGE', 21); // Enter the minimum age that your
website visitors must be to view your content (replace 18 with
your number)
define('COOKIE_DAYS', 30); //Enter the number of days you
would like the cookie to last (replace 30 with your number)
// BE CAREFUL EDITING ANYTHING BELOW THIS LINE //
date_default_timezone_set('America/Los_Angeles');
function get_birth_drops($year = '', $month = '', $day = '')
{
$out = '';
$year = $year ? $year : '';
$month = $month ? $month : '';
$day = $day ? $day : '';
$month_select = '<label>MM: <select name="bmonth"
id="bmonth"><option value=""></option>';
for($i = 1; $i <=12; $i ++)
{
$selected = ($i == $month) ? ' selected':'';
$month_select .= '<option value="' . $i . '"' .
$selected . '>' . $i . '</option>';
}
$month_select .= '</select></label>';
$day_select = ' <label>DD: <select name="bday"
id="bday"><option value=""></option>';
for($i = 1; $i <=31; $i ++)
{
$selected = ($i == $day) ? ' selected':'';
$day_select .= '<option value="' . $i . '"' .
$selected . '>' . $i . '</option>';
}
$day_select .= '</select></label>';
$year_select = ' <label>YYYY: <select name="byear"
id="byear"><option value=""></option>';
for($i = 2010; $i >= 1950; $i --)
{
$selected = ($i == $year) ? ' selected':'';
$year_select .= '<option value="' . $i . '"' .
$selected . '>' . $i . '</option>';
}
$year_select .= '</select></label>';
$out = $month_select . $day_select . $year_select;
return $out;
}
function calculateAge($birthday){
return floor((time() - strtotime($birthday))/31556926);
}
?>
Any thoughts? Thanks a ton!

No comments:

Post a Comment