Firefox prompt: the page you are trying to view cannot be displayed due to a Content Encoding Error

Source: Internet
Author: User
Tags unsupported

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, and the cause may be ob_gzhandler. I will summarize the solution below.

Firefox error code:

Content Encoding Error

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 in ob_start ('ob _ gzhandler ')

If you use ob_start ("ob_gzhandler ");
The output after ob_clean () is not displayed. This is a bug,
You can use ob_end_clean (); ob_start ("ob_gzhandler"); instead of ob_clean ();
Otherwise, the output content is empty.
<? Php
Error_reporting (E_ALL );
Ob_start ("ob_gzhandler ");
Echo "content ";
Ob_clean ();
Echo "more content ";
?>
The above Code expects to output more content, but nothing will actually be output.

The following is normal.
<? Php
Error_reporting (E_ALL );
Ob_start ("ob_gzhandler ");
Echo "content ";
Ob_end_clean ();
Ob_start ("ob_gzhandler ");
Echo "more content ";
?>

Next, we will customize a callback function and test it again.
<? Php
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 if ob_end_clean is used instead of ob_clean, the subsequent output will not be displayed.

Therefore, even the following code still uses ob_clean or ob_end_clean, leading to empty output.
<? Php
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:
<? Php
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
<Enter>
<Enter>

The following information is returned:

HTTP/1.1 200 OK
Date: Fri, 20 Feb 2009 15:40:17 GMT
Server: Apache/2.2.6 (Win32) PHP/5.2.5
X-Powered-By: PHP/5.2.5
Vary: Accept-Encoding
Content-Length: 12
Connection: close
Content-Type: text/html

More content

The connection to the host is lost.

It can be seen that more content has been output

 

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.