[Crash] Unicode signature Bom-related incidents

Source: Internet
Author: User

From http://www.xij.cn/blog? P = 119

 

 

Unicode signature BOM

I have encountered such a problem in front-end development. I leave a line blank for no reason in IE, while in Firefox, it is normal. Why can't you find out, because there is no problem at all. You may use the include file here. Usually the header and footer will do this. The "include Unicode signature Bom" option on the page property of the file inclusion page is checked, so I will tell you that this is the accident caused by this Bom.

Today, I encountered another BOM accident while writing a JS script.
I inserted an external Js in the page, and there was such a sentence $. getjson ("/My/newmsg", function (data) {alert (data) ;}); other browsers can pop up the content normally, but there is no dynamic content under IE, I 've been depressed for nearly an hour. I suspect this sentence is wrong. I suspect that the JSON data format is wrong...
Then I suspected that the code was wrong, so I checked out the hateful BOM and removed the miracle from the dark clouds.
Although I am very lazy and seldom update my blog, I have to record it, because it is so unexpected that JS will also cause an accident due to Bom--|

The Unicode specification has the concept of BOM.
Bom is short for byte order mark, that is, byte order mark, which cannot be seen in a common text editor. Can it be said that it is a file header? Can be seen in the binary editor? This may be the case.
There is a character named "Zero Width no-break space" in the UCS encoding, and its encoding is feff. Fffe does not exist in the UCs, so it should not appear in actual transmission. We recommend that you first transmit the character "Zero Width no-break space" before transmitting the byte stream ". In this way, if the receiver receives feff, it indicates that the byte stream is big-Endian; if it receives fffe, it indicates that the byte stream is little-Endian. Therefore, the character "Zero Width no-break space" is also called Bom.
The UTF-8 does not need BOM to indicate the byte order, but BOM can be used to indicate the encoding method. The UTF-8 code for the character "Zero Width no-break space" is ef bb bf. So if the receiver receives a byte stream starting with ef bb bf, it will know that this is UTF-8 encoding. Windows uses BOM to mark the encoding of text files.

 

 

 

 

From http://liangchuanfei011.blog.163.com/blog/static/3184295820076106442981/

Warning cannot send session cookie-headers already sent... Problem Solving (problem caused by UTF-8 BOM of PHP)

I am used to using edit plus for PHP programming, so sometimes some unknown errors may occur, which is very troublesome;
Recently, the following problems always occur on some pages during project development:

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 started at E: \ WEB \ apache2 \ htdocs \ index. PHP: 1) in E: \ WEB \ apache2 \ htdocs \ functions \ sessions. PHP on line 67
After detailed search, the following causes are obtained:
In my edit plus settings, the default encoding is UTF-8, And the utf_8 signature is: always add a signature;
Therefore, try the following operations:
In the edit plus tool> parameter> File> utf_8 signature, change the option "always add signature" to "always remove signature" and open index. PHP file, save it as a new one, and re-run the script, and finally it will work properly;

In addition, I found two useful articles on the Internet.ArticleHope someone can solve this problem perfectly!

A UTF-8 BOM caused by PHP strange problem I,

// --- A. php
<? PHP
Header ("Content-Type: image/BMP ");
Session_start ();
................
?>
Save a. php as UTF-8. the following error occurs when you access the PHP file in a browser:
Warning: session_start () [function. Session-start]: cannot send session cache limiter-headers already sent (output started

At ×××. php: 1) In ××× on line 2

This problem is common, most of which are output before session_start! For laruence, this error basically does not happen, but if you use DW or editplus

CompileCodeThis error may occur even to the experts!

As shown in the preceding figure, there are no output statements in line 2 of the XXX file and line 2 of the XXX file, it's strange. Why?
Originally:

Unicode signature (BOM) can include the byte sequence mark (BOM) in the document ). Bom is two to four bytes at the beginning of a text file. It can be identified as Unicode.

The byte sequence of the subsequent bytes. Because the UTF-8 does not have a byte order, you can choose to add a UTF-8 Bom. This is required for UTF-16 and UTF-32.
No! If this option is selected, 2 to 4 bytes will be output at the beginning of the page!

Session_start () requires no output to the client browser before.

II,

Another error may occur, for example:
/-- A. php --
?>
Empty row
Empty row

This problem also occurs when you include a. php files. We recommend that you do not include the files that are often included at the end?>

Another example:
No output is allowed before session_start () is called. For example, the following is an error.
Incorrect.
========================================================== =
1 line
2 rows <? PHP
3 rows session_start (); // output already exists in the first row
4 rows .....
5 rows?>
========================================================== =

It is indeed so strange that it has been tested.
III,

Session_start ()
Set_cookie ()
Header ()
The preceding @ should be used to suppress this warning.

IV,

In the editplus Editor, If you first convert the. php file of UTF-8 to gb2312 or another file, and then convert it to UTF-8, the file can be accessed successfully, that is

Bom is removed, at this time the UTF-8 is no Bom type

PHP-session_start () error caused by UTF-8 encoding
14:55:01
large, medium, and small
when the default gb2312 encoding is used, compatible with ANSI encoding. the file header does not contain any additional information. In this case, session_start () can work properly.
when UTF Encoding is used, most editors will append a BOM block to the file header. My editplus append FF Fe, you can see it clearly in the hexadecimal Editor
. In this way, when session_start () is called, two bytes have actually been output to the browser, but the invisible character warning
the browser displays the following warning:
warning: session_start () [function. session-start]: cannot send session cookie-headers already sent by (output started ......................

Solution:
1. Manually remove the BOM block. You can edit it in a hexadecimal Editor, such as ultraedit, or use the built-in functions of the editor. A good editor generally provides the option of removing the BOM block.
2. Write a script to correct it. For different editors, the BOM header is defined as follows:
UTF-8 EF BB BF
UTF-16 big endian Fe FF
Little endian FF Fe UTF-16
UTF-32 big endian 00 00 Fe FF
UTF-32 little endian FF Fe 00

 

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.