我想做一个简单的 PHP 脚本,这是我的主页。我希望用户输入他们的出生日期或从下拉日历中选择它,然后根据他们输入的内容我可以检查他们是否是 21 岁。如果不是,我将它们发送到一个页面,如果它们是,我将它们发送到另一个页面。这是我到目前为止所拥有的。
<div id="age">
You must be 18 or older to view this site.<br>
You must be 18 or older to view this site.<br>
<form action="#" method="post">
Please input your date of birth:
<input type="text" name="month">
<input type="text" name="day">
<input type="text" name="year">
<input type="submit" name="submit" value="Verify Age">
</form>
</div>
<p></p>
<?php include "footer.php" ?>
<?php
$month = $_REQUEST['bmonth'];
$day = $_REQUEST['day'];
$year = $_REQUEST['year'];
$this_day = date(d);
$this_month = date(m);
$this_year = date(Y);
$day_val = $this_day - $day;
$month_val = $this_month - $month;
$year_val = $this_year - $year;
if (!empty($_POST['submit'])) {
$today = date_create('today');
$birth = date_create("{$_POST['year']}-{$_POST['month']}-{$_POST['day']}");
$age = date_diff($today, $birth)->y;
if ($age >= 18) {
header('Location: home.php');
} else {
header('Location: contact.php');
}
}
?>