How to solve the "cannot send session cache limiter-headers already sent" error

Source: Internet
Author: User
Tags ultraedit zen cart

Session_start ();

 

If cookie-based session is used, the browser cannot output any output before Session_start () is used, otherwise, the "Cannot send session cache limiter-headers already sent" error may occur. Therefore, make sure that Session_start () is executed before the output starts. Generally, it is directly placed at the top of the PHP file.

If Session_start () is already at the top of the file and the PHP file is UTF-8 encoded, this error is probably caused by the UTF-8 BOM of the PHP file, you need to set your editor to not add BOM when editing the UTF-8 file.

Use UlterEdit to switch to the hexadecimal editing mode and replace the first three bytes (that is, the damn ef bb bf) with 20, save (note that the automatic backup function is disabled during storage), switch to the default editing mode, and remove the first three spaces.

Or create a new file to COPY all the code.

 

The following is an introduction.

 

BOM (Byte Order Mark) is the standard Mark used in the UTF Encoding scheme to Mark the encoding. In the UTF-16, It is ff fe, and the UTF-8 becomes ef bb bf. This flag is optional because UTF8 bytes are not sequential, so it can be used to detect whether a byte stream is UTF-8 encoded. Microsoft does this kind of detection, but some software does not do this kind of detection, and treats it as a normal character.

Microsoft added ef bb bf three bytes before its own text file in UTF-8 format, the notepad and other programs on windows are based on these three bytes to determine whether a text file is ASCII or UTF-8, but this is only a mark by Microsoft, other platforms do not make such a mark on UTF-8 text files.

That is to say, a UTF-8 file may have BOM, there may be no BOM, so how to distinguish? Three methods. 1, open the file with a UltraEdit-32, switch to the hexadecimal editing mode, check whether the file header ef bb bf. 2. Open it with Dreamweaver and check the page properties to see if there is a check mark before "including Unicode signature BOM. 3, open with Windows notepad, select "Save as", see the default file encoding is UTF-8 or ANSI, if it is ANSI without BOM.

I found in the template file of Zen Cart html_header.php, found that the file does not carry BOM, with the UltraEdit-32 to save the way to add BOM, then upload html_header.php, everything is normal.

Note that the default setting does not contain BOM when Convertz is used to convert a gb2312 file to a UTF-8 file. Without BOM, the above garbled characters may occur, but with BOM, you should be careful about the include file in php. ef bb bf will be added before the php byte stream, early output to the monitor may cause program errors. A solution is to save all included files as ANSI, and the main file can be a UTF-8. To remove the BOM from a file, use UlterEdit to open the file, switch to the hexadecimal editing mode, and replace the first three bytes (that is, the damn ef bb bf) with 20, save (note that the automatic backup function is disabled during storage), switch to the default editing mode, and remove the first three spaces.

In addition, I also learned a little bit of coding knowledge: the so-called unicode file is actually a UTF-16, but it just happens to be the same as the unicode code, but in terms of concept, unicode and utf are two different things, unicode is a memory encoding representation scheme, while utf is a solution for saving and transmitting unicode. The UTF-16 is also divided into two types: High Front (LE) and high behind (BE. The official utf Code also includes utf-32, which can be le and BE. Non-unicode official utf Encoding also has utf-7, mainly used for mail Transmission. The single-byte part of UTF-8 is compatible with the iso-8859-1, which is primarily forced out of some old systems and library functions that cannot properly handle the UTF-16, and for English characters, it also saves storage space (at the cost of non-English characters wasting space ). In the iso-8859-1, both utf8 and iso-8859-1 are represented in one byte, and when it represents other characters, UTF-8 uses two or three bytes.

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.