Firefox prompt: The page _ PHP Tutorial you are trying to view cannot be displayed due to a content encoding error

Source: Internet
Author: User
Tags unsupported
Firefox prompt: The page you are trying to view cannot be displayed due to a content encoding error. 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, when I asked the customer to organize a website today, firefox prompts that 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.
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.
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.
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.
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 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

Failed cannot display the page you are trying to view, because it uses an invalid or unsupported compression format, I...

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.