dongzhong5967 2012-04-13 09:44
浏览 51
已采纳

如何忽略php中的重定向错误

I got this warning in php:

Cannot modify header information - headers already sent by (output started at

When I installed mysql, apache, and php separately but when I'm using Wamp the warning does not exist and the page redirects gracefully.

I have already tried setting the error reporting to only display errors and not warnings and what happened is that the warning didn't show up but the page also didn't redirect.

I know this is already considered bad practice but my code base has a lot of these codes and modifying them all might introduce new bugs to the code. Is there any way to completely ignore this warning in php?

  • 写回答

5条回答 默认 最新

  • doujianwan7570 2012-04-13 09:54
    关注

    The classic way to avoid - and not ignore - this problem is with output buffering, ob_start() and ob_flush(). Start the buffering before any output, and finish with the flush explicitly, or it may do so automatically. This captures any output rather than printing it, and so any headers that are output are done so before any visible content.

    Fixing the bug of things being output, from the filename you had in the error message is the best way to fix this though. Removing the closing '?>' from files when it's not needed might help.

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

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害