Cannot send session Cookie-headers already sent by when writing code with PHP (output started at e:\web\apache2\htdocs\index.php:1) in E : \web\apache2\htdocs\functi

Source: Internet
Author: User
Tags php programming

Warning cannot send session cookie-headers already sent ... Problem Solving (PHP UTF-8 BOM-related issues)

Accustomed to using Edit plus PHP programming, so sometimes there are some unknown errors, very troublesome;
Recently, when developing a project, some pages always have the following issues:

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

Warning:session_start () [Function.session-start]: Cannot send session cache Limiter-headers already sent (output Starte D at E:\web\apache2\htdocs\index.php:1) in E:\web\Apache2\htdocs\functions\sessions.php on line 67
After a detailed search, get the following reasons:
The default encoding for Utf-8 is set in my edit Plus, and the utf_8 signature is: Always add a signature;
So try these things:
In the file->utf_8 signature of the Edit Plus tool, change the option "Always add signature" to "always remove signature", then open the index.php file and re-save as, rerun the script and finally OK;

In addition, found on the Internet two more reference value of the article, I hope someone encounters this kind of situation can be solved perfectly!

A UTF-8 BOM caused by PHP's weird problem
One
---a.php
<?php
Header ("Content-type:image/bmp");
Session_Start ();
................
?>
Save a.php in utf-8 format, the result of the browser access to this PHP file, there will be the following error:
Warning:session_start () [Function.session-start]: Cannot send session cache Limiter-headers already sent (output Starte D atxxx.php:1) Inxxxon Line 2

This problem is very common, mostly because there is output before session_start! For the veteran, this error will not happen, but if you are using DW or EditPlus

If the editor writes code, even a master can have this error!

As the above tip: in the 1th line of the xxx file, xxx file 2nd line, as you see, these two will not have any output statements, very strange or error, why?
Original: The Unicode signature (BOM) can include a byte order mark (BOM) in the document. A BOM is 2 to 4 bytes at the beginning of a text file that identifies the file as Unicode and, if so, the byte order of the subsequent bytes. Because UTF-8 does not have byte order, you can choose to add a UTF-8 BOM. For UTF-16 and UTF-32, this is required.
See, No! If this option is selected, it will output 2 to 4 bytes at the front of the page!
and Session_Start () requires no output to the client browser

Second, there is another place where errors can occur, such as:
/--a.php--
?>
Blank Line
Blank Line

If you include a.php after you come back there will also be this problem, usually the advice is often included in the end of the file does not have?>
Another example: You cannot have any output before calling Session_Start (). For example, the following is an error.
==========================================
1 rows
2 rows of <? Php
3 lines session_start ();//before the first line already has output
4 lines .....
5 Row?>
==========================================
has been tested, the facts are really so bizarre.

Third, Session_Start (), Set_cookie (), header () plus @ should be able to suppress this warning.

Iv. in the EditPlus editor, if the Utf-8 a.php file is converted to gb2312 or other, and then converted to utf-8 so that it can be successfully accessed, that is, the document at the beginning of the BOM is removed, this time the UTF-8 is no BOM type


php-session_start () error caused by Utf-8 encoding problem

With the default gb2312 encoding, ANSI encoding is compatible, the header of the file has no additional information, and session_start () can work correctly at this time. When using UTF encoding, most editors attach a BOM block to the head of the file, and my editplus is attached to the FF FE, which can be clearly seen with the 16 binary editor. This way, when Session_Start () is called, it actually outputs two bytes to the browser, except that the following warning appears in the Invisible character browser:
Warning:session_start () [Function.session-start]: Cannot send session cookie-headers already sent by (output started at ......................
Workaround:
1, manual removal of BOM block, can be edited in the 16 editor, such as UltraEdit, or with the editor's own features, a good editor generally provides a choice whether to remove BOM block.
2. Write your own script corrections, which are defined for different editors, BOM headers:
UTF-8 EF BB BF
UTF-16 Big Endian FE FF
UTF-16 Little Endian FF FE
UTF-32 Big Endian (FE FF)
UTF-32 Little Endian FF FE 00 00

Cannot send session Cookie-headers already sent by when writing code with PHP (output started at e:\web\apache2\htdocs\index.php:1) in E : \web\apache2\htdocs\functi

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.