会话已保存,但页面将我踢出

时间:2014-12-18 12:58:59

标签: php session

我试图检查会话是否仍然存在,如果没有,它会将我从页面中踢出来。

session_start();
if (empty($_SESSION['locationed']))
    {
         header("Location: http://exit.php");
         die();
    }

上面的代码总是让我离开页面。

当我删除上面的代码并回显会话时:

   $locationed=$_SESSION['locationed'];

   <?php echo $locationed; ?>

它回应了我的会议地点。

有什么问题?请帮忙。

6 个答案:

答案 0 :(得分:2)

尝试isset而不是空。

if (!isset($_SESSION))
    {
         header("Location: http://exit.php");
         die();
    }

答案 1 :(得分:2)

你走了。

if (!isset($_SESSION['locationed'])) {
     header("Location: http://exit.php");
     die();
}

答案 2 :(得分:1)

尝试:

if (isset($_SESSION['locationed']))

答案 3 :(得分:1)

尝试这些组合,

if (!isset($_SESSION['locationed']) && empty($_SESSION['locationed'])) {
...
}

答案 4 :(得分:1)

session_start();
if(!isset($_SESSION["locationed"]) || empty($_SESSION['locationed']))
{
  header("Location: http://exit.php");
  die();
}

答案 5 :(得分:1)

session_start();
$_SESSION['locationed']="1234";
echo $_SESSION['locationed']; //if echo something means getting something on that
if($_SESSION['locationed'] =='' && !isset($_SESSION['locationed']))
    {
         header("Location: http://exit.php");
         die();
    }