Today, when I asked the customer to organize a website, the firefox prompt is displayed: The page you are trying to view cannot be displayed due to a content encoding error because it uses an invalid or unsupported compression format.
Today, I asked the customer to organize a website and found the firefox prompt: The page you are trying to view cannot be displayed due to a content encoding error because it uses an invalid or unsupported compression format, I think the customer is a php site, which may be caused by ob_gzhandler.
Firefox error code:The page you are trying to view cannot be displayed because it uses an invalid or unsupported compression format. contact the website owner to inform you of this problem.
Cause and solution:
1. ensure that the php program has no warning or error prompt
2. PHP code ob_start ('OB _ gzhandler') causes two reasons:
A. the server does not support this compression format. you can use function_exists ('OB _ gzhandler') to determine the solution. change ob_start ('OB _ gzhandler') to ob_start ();
B. When ob_start ('OB _ gzhandler') is used, the preceding content is output. check the preceding content and the content of the require include Call file. If it cannot be found, you can use ob_start () before calling other files, and then use ob_end_clean () to clear the output content;
3. set_magic_quotes_runtime () function:
Tip:Function set_magic_quotes_runtime () is deprecated. The cause of this prompt is that this feature is disabled after PHP5.3 and has been completely removed from PHP6, that is, this Function does not exist. You can comment out or delete the wrong row, or add the @ symbol before set_magic_quotes_runtime.
4. PHP5.30 does not support this Syntax by default. the output variable must use php echo $ username;?> Syntax. You can set short_open_tag in php. ini to On to be compatible with the original syntax.
Php bug about enabling GZIP compression for ob_start ('OB _ gzhandler,If ob_start ("ob_gzhandler") is used, the output after ob_clean () is not displayed. this is a bug. you can use ob_end_clean (); ob_start ("ob_gzhandler "); replace ob_clean (); otherwise, the output content is empty.
- Error_reporting (E_ALL );
- Ob_start ("ob_gzhandler ");
- Echo "content ";
- Ob_clean ();
- Echo "more content ";
- ?>
The above code expects that more content will not be output, and the following will be normal:
- Error_reporting (E_ALL );
- Ob_start ("ob_gzhandler ");
- Echo "content ";
- Ob_end_clean ();
- Ob_start ("ob_gzhandler ");
- Echo "more content ";
- ?>
The following custom callback function is used for testing:
- Function my_ob_gzhandler ($ buffer, $ mod ){
- Header ("Content-Encoding: gzip ");
- Return gzencode ($ buffer, 9, FORCE_GZIP );
- }
- Error_reporting (E_ALL );
- Ob_start ("my_ob_gzhandler ");
- Echo "content ";
- Ob_clean ();
- Echo "more content ";
- ?>
The above is normal, but replacing ob_end_clean with ob_clean will cause the subsequent output to not be displayed. Therefore, even if the following code still uses ob_clean or ob_end_clean, the output will be empty.
- If (ini_get ('zlib. output_compression ')){
- If (ini_get ('zlib. output_compression_level ')! = 9 ){
- Ini_set ('zlib. output_compression_level ', '9 ');
- }
- Ob_start ();
- } Else {
- If (strstr ($ _ SERVER ['http _ ACCEPT_ENCODING '], "gzip ")){
- Ob_start ("ob_gzhandler ");
- } Else {
- Ob_start ();
- }
- }
- ?>
The most stable method for enabling page compression should be similar to the following:
- If (extension_loaded ('zlib ')){
- Ini_set ('zlib. output_compression ', 'on ');
- Ini_set ('zlib. output_compression_level ', '3 ');
- }
- ?>
However, if you must use ob_gzhandler to enable page compression, pay attention to the first sentence in this article. In fact, the following code is not displayed in the browser:
- Error_reporting (E_ALL );
- Ob_start ("ob_gzhandler ");
- Echo "content ";
- Ob_clean ();
- Echo "more content ";
But if you test
- Telnet localhost 80
- GET/test. php HTTP/1.0
The following information is returned:
HTTP/1.1 200 OKDate: Fri, 20 Feb 2009 15:40:17 GMTServer: Apache/2.2.6 (Win32) PHP/5.2.5X-Powered-By: PHP/5.2.5Vary: Accept-EncodingContent-Length: 12 Connection: closeContent-Type: text/htmlmore content
If the connection to the host is lost, we can see that more content has been output.