我正在使用一个非常有效的脚本来验证我正在开发的网站的年龄。目前它使用下拉菜单来选择月、日、年。我希望可以更改下拉菜单以让用户输入月、日、年。
这是代码:
<?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);
}
?>
有什么想法吗?万分感谢!