Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

PHP has an error Warning: what about Cannot modify header information-headers already sent by

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you PHP error Warning: Cannot modify header information-headers already sent by how to do, I believe most people do not understand, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!

This error was encountered while testing the following code today:

Session_start ()

$_ SESSION ['username'] = $username

Echo "location.href='../admin.php';"

Exit ()

An error occurred:

Warning: Cannot modify header information-headers already sent by...

After reading some online methods, we did not encounter this error when configuring output_buffering to 4096 by default in php.ini:

Output_buffering setting description:

Off: indicates that PHP output cache is turned off

On: open infinite output cache

4096: open the output cache with the size of 4096Byte

By default, php buffer is on, and the default value for this buffer is 4096, or 4kb. You can find the output_buffering configuration in the php.ini configuration file. When echo,print and others output user data, the output data will be written to php output_buffering until the output_buffering is full, and the data will be transmitted to the browser through tcp for display. You can also manually activate the php output_buffering mechanism through ob_start () so that even if the output exceeds the 4kb data, you don't really send the data to the tcp to the browser, because ob_start () sets the php buffer space to be large enough. The data is not sent to the client browser until the script ends, or until the ob_end_flush function is called.

For more information about output_buffering, please refer to:

Https://www.jb51.net/article/55707.htm

Add: of course, you can also solve this problem by removing BOM, and it is recommended to encode in UTF-8 BOM-free format. Thank you @ ihipop Children's shoes

With regard to BOM, simply put, the software uses BOM to identify whether the file is UTF-8 encoded. In earlier versions of Firefox, extensions could not have BOM, but BOM has been supported since Firefox 1.5. Now it turns out that PHP doesn't support BOM either. PHP was not designed with BOM in mind, which means that he will not ignore the three characters at the beginning of the BOM in the UTF-8-encoded file.

Another trouble is mentioned: "due to the limitation of the COOKIE export mechanism, COOKIE cannot send out files that already have BOM at the beginning of these files (because PHP has already sent the file header before COOKIE is sent), so the login and logout functions are invalid. All functions that rely on COOKIE and SESSION are invalid." This should be why a blank page appears in the Wordpress background. Because any executed file contains BOM, these three characters will be sent out, resulting in the invalidation of functions that rely on cookies and session, so you may also encounter the following error:

Warning: session_start () [function.session-start]: Cannot send session cookie-headers already sent by (output started at E:\ web\ index.php:1) in E:\ web\ functions\ sessions.php on line 39

The above is all the contents of the article "PHP error Warning: what to do with Cannot modify header information-headers already sent by". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report