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条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作