doutou3725 2013-06-10 14:11
浏览 43

传递PHP会话

I am having problems passing session variables all of the sudden and I don't know what I'm doing wrong. See my test code below for createSession.php and passingSession.php. I can create the session ok on createSession.php but when I click the link to see if the session is passing to passingSession.php, the session is now empty.

Note: session_start() is the very first thing on each page. No leading white space of any kind.

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条回答 默认 最新

  • doupang5433 2013-06-10 14:28
    关注

    Don't use if($_SESSION['aID']=="") to test if a session exists but use isset(). You are comparing your session variable to an empty string which is different from an unset variable.

    Use something like this:

    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."; 
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀