传递PHP会话

时间:2013-06-10 14:11:52

标签: php

我遇到突然传递会话变量的问题,我不知道我做错了什么。请参阅下面的测试代码,了解createSession.php和passingSession.php。我可以在createSession.php上创建会话ok但是当我单击链接以查看会话是否传递给passingSession.php时,会话现在是空的。

注意:session_start()是每个页面上的第一件事。没有任何领先的白色空间。

createSession.php

session_start();

$_SESSION['aID'] =  time();

if($_SESSION['aID']==""){
    echo "Session is empty. There is a problem creating sessions";
}else{
    echo "Session = ".$_SESSION['aID']." There is no problem creating sessions.  <a href='passingSession.php'>Click Here</a> to see if sessions are passing ok.";   
}

passingSession.php

session_start();

if($_SESSION['aID']==""){
    echo "Session is empty. There is a problem passing sessions.";
}else{
    echo "Session = ".$_SESSION['aID'].". Passing sessions is ok."; 
}

2 个答案:

答案 0 :(得分:1)

不要使用if($ _ SESSION ['aID'] ==“”)来测试会话是否存在但使用isset()。 您正在将会话变量与空字符串进行比较,该字符串与未设置的变量不同。

使用类似的东西:

session_start();

if(!isset($_SESSION['aID'])){
    echo "Session is empty. There is a problem passing sessions.";
}else{
    echo "Session = ".$_SESSION['aID'].". Passing sessions is ok."; 
}

答案 1 :(得分:0)

这是托管配置问题。修改和会话现在再次正常工作。谢谢Carlos Campderros