douhuitan5863 2015-11-23 23:17
浏览 51
已采纳

Laravel 4.2简单会话逻辑不起作用

This is very simple session logic. I don't know why this isn't working. Here the code.

if(Session::get('sign_up_data')){
    echo 1;
}else{
    echo 2;
    Session::put('sign_up_data',21);
}
exit;

Always echoing 2 every time i reload the page. I am expecting echoing 2 on first load then the next 1 and 1 and 1 and soon. Tried different approach but still getting the same result. Do you any idea guys?

  • 写回答

2条回答 默认 最新

  • dongxi1680 2015-11-23 23:30
    关注

    If you kill the application mid-cycle (through exit, dd, etc.), the session data won't write. Remove the exit, and you are good.

    If you need to kill the script mid-cycle, then save the session data manually. So, in other words, this works:

    if(Session::get('sign_up_data')){
        echo 1;
    }else{
        echo 2;
        Session::put('sign_up_data',21);
    }
    // exit;
    

    If you are going to kill the script, then call save manually like this:

    if(Session::get('sign_up_data')){
        echo 1;
    }else{
        echo 2;
        Session::put('sign_up_data',21);
        Session::save();
    }
    exit;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题