douwa1304 2013-06-05 01:44
浏览 41

PHP保持重定向而不保存会话

Okay I created an age gate that runs the age calculation from the form fine, but as soon as it starts working with the redirect things go crazy. First of all when I load up the verify.php page on my localhost it first reloads the page when I hit the submit button after filling out the age information. Then I do it again and the redirect works? It works when taking me to the outside website, but then when I actually get the age verification correct it takes me to index.php but then index.php redirects me to the verify.php page again until the browsers start to complain about the redirect cookie issue. I don't get why its not creating the session at least temporarily.

so I have the php in the verify.php form page so its all on the same page here

VERIFY.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);
}
}
?>

INDEX.PHP

<?php
session_start();

if(!isset($_SESSION['verifyok'])){
header("location: verify.php");
exit;
}
?>

Thanks in advance for the support!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
    • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算