澳门新葡萄京娱乐场php Cannot modify header informationheaders already sent by解决方法

HTMLHEADTITLE php调用js文件的好措施/TITLE/HEADBODYscrīpt
language=”javascrīpt” type=”text/javascrīpt”
src=”test.php”/scrīptscrīptok(aaaaaa!);/scrīpt/BODY/HTMLtest.php:?phpecho
function ok(msg){alert(msg);};?

风度翩翩经在施行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();

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();
?>

另黄金年代篇小说

<?php
ob_start();
setcookie(“username”,”宋岩宾”,time()+3600);
echo “the username is:”.$HTTP_COOKIE_VARS[“username”].”n”;
echo “the username is:”.$_COOKIE[“username”].”n”;
print_r($_COOKIE);
?>
Warning: Cannot modify header information – headers already sent
by出错的缘故
作者在php程序的尾部加了,

header(“cache-control:no-cache,must-revalidate”);

从此以后页面就现身下面的荒诞,看了N个资料也远非结果。前些天有时发掘原先是自家的php.ini里面的安插出了难点,在C:windows下找到php.ini文件
output_buffering默认为off的。

小提示,还应该有三个更加好的清除办法就是在php.ini 然后把 output_buffering
设为 on […]就不会鬼使神差这类难题了。

发表评论

电子邮件地址不会被公开。 必填项已用*标注