0

我有一个大问题,我无法解决。我的会话变量在文件之间交换,但在刷新第二页后它们消失了。

这是代码:

索引.php

session_start();

header('Title: So random');
header('charset: UTF-8');

//if index.php?login is requested
if(isset($_REQUEST['login'])) {

    //'pass' input box value (from POST) is saved to $pass variable.
    $pass = $_POST['password'];

    //if pasword matches Password.
    if($pass == 'Password') {

        //session_start();

        $_SESSION['logintoken'] = "approoved";
        header("Location: list.php");
        die();

    } else { $error = true; }

}

if(isset($_SESSION['logintoken'])) { 
        header('Location: list.php'); 
        die();
    }


?>
Random HTML With login page goes here...

然后我们有页面,该页面仅适用于登录。从登录重定向到它之后没关系,但刷新后我有“未定义登录令牌”。

列表.php

<?php
session_start();

if($_SESSION['logintoken'] != "approoved") { 
    //'<meta http-equiv="REFRESH" content="0; url=index.php">'
    die();
}

?>
<html> goes here....
4

1 回答 1

0
header('Title: So random');
header('charset: UTF-8');   
$_SESSION['logintoken']='' ;

编辑:也许这更好

if(isset($_SESSION['logintoken']) && ($_SESSION['logintoken'] != "approoved"))

编辑2:

    header("Location: list.php?token=".$_SESSION['logintoken']);

列表.php

if($_REQUEST['token'] != "approoved") { 
    //'<meta http-equiv="REFRESH" content="0; url=index.php">'
    die();
}
于 2013-03-17T04:54:36.993 回答