search
HomeBackend DevelopmentPHP Tutorial使用ob_flush提示:E_WARNING: Cannot modify header information

使用ob_flush提示:E_WARNING: Cannot modify header information - headers already sent 
请问如何解决?

代码如下:
echo $show_msg."<script>$script</script>";
ob_flush();
flush();


回复讨论(解决方案)

BOM头吧。

错误提示已经写的很清楚了,响应头已经输出,所以不能再修改头信息

应该是你没有新开一层ob,直接输出了数据(同时输出了响应头),默认就直接送出到浏览器了

使用ob正常情况下是先将数据写在ob里面,当写完后再输出ob里面的内容.

错误提示已经写的很清楚了,响应头已经输出,所以不能再修改头信息

应该是你没有新开一层ob,直接输出了数据(同时输出了响应头),默认就直接送出到浏览器了

使用ob正常情况下是先将数据写在ob里面,当写完后再输出ob里面的内容.

简单的说就是你可能没有使用ob_start

function flush_buffers(){     ob_end_flush();     ob_flush();     flush();     ob_start(); } 


错误提示已经写的很清楚了,响应头已经输出,所以不能再修改头信息

应该是你没有新开一层ob,直接输出了数据(同时输出了响应头),默认就直接送出到浏览器了

使用ob正常情况下是先将数据写在ob里面,当写完后再输出ob里面的内容.

简单的说就是你可能没有使用ob_start

具体怎么用呀?我是在phpwind上面开发的。他前面一个insert操作,搞不懂为何弄个输出出来,我翻遍了代码也没发现哪里有输出。总之,我是无法改变他输出这个事实了,我无法改变他的代码。我是在他后面使用flush的。有什么解决方法吗?

function flush_buffers(){     ob_end_flush();     ob_flush();     flush();     ob_start(); } 


用了,还是出错呀。

我是在phpwind上面开发的。他前面一个insert操作,搞不懂为何弄个输出出来,我翻遍了代码也没发现哪里有输出。总之,我是无法改变他输出这个事实了,我无法改变他的代码。我是在他后面使用flush的。有什么解决方法吗?

BOM头吧。
前面应该是有输出了。有没有什么函数可以忽略前面的输出?好像记得有。ob_end_flush、ob_flush、 flush、ob_start这些总把我搞得晕头转向

ob_flush(); 是推出缓存,不可能出现你说的问题
只有 header、session_start、setcookie 才可能出现
E_WARNING: Cannot modify header information - headers already sent 

请你认真检查一下错误信息所提示的出错地点

ob_flush(); 是推出缓存,不可能出现你说的问题
只有 header、session_start、setcookie 才可能出现
E_WARNING: Cannot modify header information - headers already sent 

请你认真检查一下错误信息所提示的出错地点

你说的有道理,如果前面因为输出导致报错的话,我自己输出的早就报错了。但出错的确是ob_flush这行。
我怀疑前面是不是有Ob_Start('ob_gzhandler');这些类似的代码了。

ob_flush(); 是推出缓存,不可能出现你说的问题
只有 header、session_start、setcookie 才可能出现
E_WARNING: Cannot modify header information - headers already sent 

请你认真检查一下错误信息所提示的出错地点

假如让你在

echo 'sd';ob_flush(); flush(); 

这段代码的前面加上一行什么代码让他出错。你会加什么代码?

除非出现语法错误,#10 的代码前加什么都不会出错!
但是在后面加 header、session_start、setcookie 之一,就可能出错了

你最好贴出完整的错误信息

除非出现语法错误,#10 的代码前加什么都不会出错!
但是在后面加 header、session_start、setcookie 之一,就可能出错了

你最好贴出完整的错误信息

我找到问题的答案了。是我那行代码阻碍了系统的报错,而不是系统影响了我那行代码的运行。报错信息如下:

Uncaught error with message 'E_WARNING: Cannot modify header information - headers already sent by (output started at E:\AppServ\www\phpwind\upload\src\extensions\pwpick\service\srv\helper\AdminOutputHelper.php:323)'The server encountered an internal error and failed to process your request. Please try again later. If this error is temporary, reloading the page might resolve the problem. If you are able to contact the administrator report this error message.(http://www.windframework.com/)


这个报错信息是phpwind自己搞出来的,他自己有个函数专门搞这个

/**	 * 错误视图渲染	 * 	 * @param array $__vars	 */	private function render($__vars, $errorcode, $errDir, $errPage) {		@extract($__vars, EXTR_REFS);		unset($__vars);		ob_start();		$this->getResponse()->setStatus($errorcode);		$this->getResponse()->sendHeaders();		require $errDir . '/' . $errPage . '.htm';		exit();	}


看到$this->getResponse()->sendHeaders();这行了吗?我前面有输出了,他再搞这行就出错了。我被他报错在 ob_flush();这个误导了。

谢谢大家的关注。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use