六子技术网首页

六子技术网

  • 网站首页
  • HTML/CSS
  • javascript
  • seo优化
  • PS美工
  • 系统安全
  • 漏洞预警
  • 编程学习
  • 原创专区
  • 【六子技术网】是一家综合技术门户,为您提供网站建设,编程开发,安全维护,漏洞预警等技术文章

    技术文章MAP

    文章

    如果在执行php程序时看到这条警告:"Warning: Cannot modify header information - headers

    日期:2019/12/3 12:38:03来源分类:编程开发

    如果在执行php程序时看到这条警告:"Warning: Cannot modify header information - headers already sent by ...."

    Few notes based on the following user posts:
    有以下几种解决方法:

    1. Blank lines (空白行):
    Make sure no blank line after <?php ... ?> of the calling php scrīpt.
    检查有<?php ... ?> 后面没有空白行,特别是include或者require的文件。不少问题是这些空白行导致的。

    2. Use exit statement (用exit来解决):
    Use exit after header statement seems to help some people
    在header后加上exit();
    header ("Location: xxx");
    exit();

    3. PHP has this annoying problem, if your HTML goes before any PHP code or any header modification before redirecting to certain page, it ll said "Warning: Cannot modify header information - headers already sent by ...." Basically anytime you output to browser, the header is set and cannot be modified. So two ways to get around the problem:

    3a. Use Javascrīpt (用Javascrīpt来解决):
    <? echo "<scrīpt> self.location( file.php );</scrīpt>"; ?>
    Since it s a scrīpt, it won t modify the header until execution of Javascrīpt.
    可以用Javascrīpt来代替header。另外需要注意,采用这种方法需要浏览器支持Javascrīpt.

    3b. Use output buffering (用输出缓存来解决):
    <?php ob_start(); ?>
    ... HTML codes ...
    <?php
    ... PHP codes ...
    header ("Location: ....");
    ob_end_flush();
    ?>

    本文由六子技术网小编:小熊编辑整理 - 转载请注明来源 - http://www.liuzi.net/bc/html/3997.html

    随机推荐

    • 该分类还没有添加任何内容!
    • 该分类还没有添加任何内容!

    Copyright 2005-2019 【六子技术网】 版权所有 黑ICP备16886888号

    声明:本站所有文章来自互联网 如有异议 请联系本站管理员