1
我有一个年龄门建立在我的网站,让17岁以下的用户无法进入现场,但我想要的人,谁已经收藏特定的链接才能进入该链接经过年龄门后:HTTP推荐通过年龄门
这里是我的年龄门代码:
<?php
session_start();
if(isset($_SESSION['legal'])) { # Check to see if session has already been set
$url = ($_SESSION['legal'] == 'yes') ? 'index.php' : 'message.php';
header ('Location: ' .$url);
}
// If visitor hasn't gone through the age gate - Age Gate function and Set Session//
if(isset($_POST['checkage'])) {
$day = ctype_digit($_POST['day']) ? $_POST['day'] : '';
$month = ctype_digit($_POST['month']) ? $_POST['month'] : '';
$year = ctype_digit($_POST['year']) ? $_POST['year'] : '';
$birthstamp = mktime(0, 0, 0, $month, $day, $year);
$diff = time() - $birthstamp;
$age_years = floor($diff/31556926);
if($age_years >= 18) {
$_SESSION['legal'] = 'yes';
$url = 'index.php';
} else {
$_SESSION['legal'] = 'no';
// If failed the Age Gate go to specific page
$url = 'message.php';
}
header ('Location: ' .$url);
}
?>
我能加入这个代码,所以,如果我想去域/ page.php文件或域/子目录/ - 通过之后,Age Gate会带我去那里吗? (我知道我必须使用HTTP Referrer,但我无法弄清楚如何包含它)。
编辑补充:我知道,有时浏览器不会保存/发送HTTP推荐,所以我需要为那些谁不传递价值的解决方案。
编辑:基于表单提交年龄计算 -
$day = ctype_digit($_POST['day']) ? $_POST['day'] : '';
$month = ctype_digit($_POST['month']) ? $_POST['month'] : '';
$year = ctype_digit($_POST['year']) ? $_POST['year'] : '';
$birthstamp = mktime(0, 0, 0, $month, $day, $year);
$diff = time() - $birthstamp;
$age_years = floor($diff/31556926);
如果你只存储在会话你的年龄门,它不会被浏览器会话之间持续存在(即如果他们重新启动他们的浏览器)。您可能会考虑使用cookie或其他方式。 – jchapa 2013-03-25 18:02:01