好的,我创建了一个年龄门,可以很好地从表单中运行年龄计算,但是一旦它开始使用重定向,事情就会变得疯狂。首先,当我在本地主机上加载 verify.php 页面时,当我在填写年龄信息后点击提交按钮时,它首先重新加载页面。然后我再做一次并且重定向有效吗?它在将我带到外部网站时有效,但是当我真正得到正确的年龄验证时,它会将我带到 index.php 但随后 index.php 再次将我重定向到 verify.php 页面,直到浏览器开始抱怨重定向饼干问题。我不明白为什么它至少暂时不创建会话。
所以我在 verify.php 表单页面中有 php,所以它都在同一个页面上
验证.PHP
<?php
session_start();
if(isset($_SESSION['verifyok']))
{
header("location: index.php");
exit(0);
}
if(isset($_SESSION['verifyfail']))
{
header("location: http://www.centurycouncil.org/");
exit(0);
}
if($_POST)
{
$remember = $_REQUEST ['remember'];
$day = $_POST ['day'];
$month = $_POST ['month'];
$year = $_POST ['year'];
$country = $_POST ['country'];
$birthday = mktime(0,0,0,$month,$day,$year);
$difference = time() - $birthday;
$age = floor($difference / 31556926);
if($age >= 21)
{
$_SESSION ['verifyok'] = 1;
header ("location: index.php");
exit(0);
}
else
{
$_SESSION ['verifyfail'] = 0;
header("loaction: http://www.centurycouncil.org/");
exit(0);
}
if($remember == 'save')
{
setcookie("verifyok", 1,mktime(0,0,0,01,01,date("Y")+30));
$_SESSION ['verified'] = 1;
header("location: index.php");
exit(0);
}
}
?>
索引.PHP
<?php
session_start();
if(!isset($_SESSION['verifyok'])){
header("location: verify.php");
exit;
}
?>
提前感谢您的支持!