du248227 2015-06-28 20:25
浏览 19
已采纳

仅在使用Bootstrap时无法修改标头

Alright, I was not able to find a problem like mine anywhere else, so here it is.

I am using a login function to login a user. After they put their data in, I send it through the function. This then returns values based on the result, which is used by a switch to display results to the user. If they get logged in, a cookie is set in the function. The switch then uses header('Location: /') to redirect the user.

The problem with this is that when I try using Bootstrap, it throws this error:

Warning: Cannot modify header information - headers already sent by
(output started at C:\wamp\www\assets\php\header.php:89) in
C:\wamp\www\assets\classes\Shortener.php on line 163

header.php; line 89: <br/><br/><br/> (this is the end of the file)

Shortener.php (login function); line 163:

setcookie('session', $db_session_hash, time()+3600, "/");


If I remove the bootstrap parts of this, it works absolutely fine! (which angers me the most)

header.php: https://pastebin.com/jnGtHSUy

Shortener.php (login function only): https://pastebin.com/i6CG54hw

I hope this is enough information. I've been angry at this ever since I've been getting this error.

  • 写回答

2条回答 默认 最新

  • dtn36013 2015-06-28 20:55
    关注

    Somehow your login function is being called partway through the page, instead of before the header file is included. There are 2 ways to solve this, Zak:

    1. Set the cookie first (by making sure that login() is always called before the template data), before you include any HTML. Shortly after you begin to output the page content (header content in this case), the server will output the HTTP headers (where the cookie should be), and then the HTML content. As soon as the server sends the headers, you can no longer set cookies.

    2. You can increase the output buffering as set in your php.ini file. I think I have mine set at 4096, but higher values mean more HTML content before the headers are sent. This is why the Bootstrap lines are the difference between overrunning the output buffer before you set your cookie or not overrunning the buffer's space. Now, this is a lousy solution albeit a handy piece of knowledge.

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

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集