doufu3718 2011-02-26 16:05
浏览 58
已采纳

PHP:防止标头和session_start

I've built my own educational MVC framework to learn more about PHP OOP, which I certainly have, but for the moment I have gotten myself into a pickle. I need to use sessions throughout most of the project, but also need to stream a file to the user at a certain page.

As I call session_start() by default before getting into my controller, I get the infamous Headers already sent thrown in my face when I need to stream a file from inside the controller to the user. Pretty logical.

As I make the session modification inside the controllers, I need the session_start() to be called in beforehand, but at that time, the controller obviously isn't loaded and there's no way my framework could tell whether It should call the session_start() or not. Creating a file with a white list of controller names that doesn't need sessions seems quite primitive.

What would be an appropriate way to get rid of sessions when I need to stream a file?

  • 写回答

4条回答 默认 最新

  • douchuza8908 2011-02-26 16:17
    关注

    Starting the session belongs in the bootstrap, not in an object IMO.

    I would tend to always start in one of the first lines of the bootstrap, regardless whether it will be needed in the current script or not. Performance implications are likely to be non-existent or minimal.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面