Home php教程 php手册 firefox提示:内容编码错误 无法显示您尝试查看的页面

firefox提示:内容编码错误 无法显示您尝试查看的页面

Jun 13, 2016 am 09:57 AM
firefox content client try you hint tidy show check coding website mistake page

今天打帮客户整理一个网站时发现在firefox提示:内容编码错误 无法显示您尝试查看的页面,因为它使用了无效或者不支持的压缩格式了,我一看客户是php站,导致原因可能是ob_gzhandler原因,下面我来总结了解决办法。

firefox错误码:

内容编码错误

无法显示您尝试查看的页面,因为它使用了无效或者不支持的压缩格式。

请联系网站的所有者以告知此问题

 
错误原因和解决办法:

1、保证php程序没有任何警告或出错的提示

2、PHP代码ob_start('ob_gzhandler')导致的,导致的原因有两种:
      a、服务器不支持这种压缩格式,可使用function_exists('ob_gzhandler')判断,解决方法 ob_start('ob_gzhandler')改为ob_start();
      b、使用ob_start('ob_gzhandler')时候前面已经有内容输出,检查前面内容以及require include调用文件的内容。若无法找到可以在调用其它文件前使用ob_start(),调用之后使用 ob_end_clean () 来清除输出的内容;

3、set_magic_quotes_runtime()函数:
提示:Function set_magic_quotes_runtime() is deprecated,导致这个提示的原因是在PHP5.3后此特性已经关闭,在PHP6中已经完全移除此特性,也就是这个函数已经不存在了。你可以注释 或者删除掉出错的行,或者是在set_magic_quotes_runtime()前面加@符号。

4、PHP5.30版本,默认不再支 持这样的语法,输出变量需使用php echo $username;?>语法才可以。你可以通过将 php.ini 中的 short_open_tag 设置为 On,以兼容原来的语法。

php关于ob_start('ob_gzhandler')启用GZIP压缩的bug

如果使用ob_start("ob_gzhandler");
则ob_clean()后面的输出将不显示,这是个bug,
可以用ob_end_clean();ob_start("ob_gzhandler"); 代替ob_clean();
否则后面输出内容将是空。
error_reporting(E_ALL);
ob_start("ob_gzhandler");
echo "content";
ob_clean();
echo "more content";
?>
上面的代码期望输出more content实际上什么内容也不会输出。

下面就正常了
error_reporting(E_ALL);
ob_start("ob_gzhandler");
echo "content";
ob_end_clean();
ob_start("ob_gzhandler");
echo "more content";
?>

下面自定义一个回调函数再测试
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";
?>
上面是正常的,但使用ob_end_clean代替ob_clean后又会导致后面的输出不会显示。

因此即使是下面的代码依然会在使用ob_clean或者ob_end_clean后会导致输出为空。
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();
   }
}
?>

最稳定的启用页面压缩的方法应该类似下面
if(extension_loaded('zlib')) {
ini_set('zlib.output_compression', 'On');
ini_set('zlib.output_compression_level', '3');
}
?>

但如果一定要使用ob_gzhandler来启用页面压缩就要注意本文的第一句话了。

事实上,下面的代码只是浏览器不显示
error_reporting(E_ALL);
ob_start("ob_gzhandler");
echo "content";
ob_clean();
echo "more content";

但如果测试一下

telnet localhost 80
GET /test.php HTTP/1.0

将会返回如下信息

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

失去了跟主机的连接。

可以看出more content已经输出

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What should I do if Google Chrome prompts that the content of this tab is being shared? What should I do if Google Chrome prompts that the content of this tab is being shared? Mar 13, 2024 pm 05:00 PM

What should I do if Google Chrome prompts that the content of this tab is being shared? When we use Google Chrome to open a new tab, we sometimes encounter a prompt that the content of this tab is being shared. So what is going on? Let this site provide users with a detailed introduction to the problem of Google Chrome prompting that the content of this tab is being shared. Google Chrome prompts that the content of this tab is being shared. Solution: 1. Open Google Chrome. You can see three dots in the upper right corner of the browser "Customize and control Google Chrome". Click the icon with the mouse to change the icon. 2. After clicking, the menu window of Google Chrome will pop up below, and the mouse will move to "More Tools"

Unable to complete operation (Error 0x0000771) Printer error Unable to complete operation (Error 0x0000771) Printer error Mar 16, 2024 pm 03:50 PM

If you encounter an error message when using your printer, such as the operation could not be completed (error 0x00000771), it may be because the printer has been disconnected. In this case, you can solve the problem through the following methods. In this article, we will discuss how to fix this issue on Windows 11/10 PC. The entire error message says: The operation could not be completed (error 0x0000771). The specified printer has been deleted. Fix 0x00000771 Printer Error on Windows PC To fix Printer Error the operation could not be completed (Error 0x0000771), the specified printer has been deleted on Windows 11/10 PC, follow this solution: Restart Print Spool

Solution to Windows Update prompt Error 0x8024401c error Solution to Windows Update prompt Error 0x8024401c error Jun 08, 2024 pm 12:18 PM

Table of Contents Solution 1 Solution 21. Delete the temporary files of Windows update 2. Repair damaged system files 3. View and modify registry entries 4. Turn off the network card IPv6 5. Run the WindowsUpdateTroubleshooter tool to repair 6. Turn off the firewall and other related anti-virus software. 7. Close the WidowsUpdate service. Solution 3 Solution 4 "0x8024401c" error occurs during Windows update on Huawei computers Symptom Problem Cause Solution Still not solved? Recently, the web server needs to be updated due to system vulnerabilities. After logging in to the server, the update prompts error code 0x8024401c. Solution 1

Why does the Xiangxiangfuzhai app display an error? Why does the Xiangxiangfuzhai app display an error? Mar 19, 2024 am 08:04 AM

The display error is a problem that may occur in the Xiangxiang Fuzhai app. Some users are not sure why the Xiangxiang Fuzhai app displays errors. It may be due to network connection problems, too many background programs, incorrect registration information, etc. Next, This is the editor’s introduction to how to solve app display errors for users. Interested users should come and take a look! Why does the Xiangxiang Fuzhai app display an error answer: network connection problem, too many background programs, incorrect registration information, etc. Details: 1. [Network problem] Solution: Check the device connection network status, reconnect or choose another network connection to use. Can. 2. [Too many background programs] Solution: Close other running programs and release the system, which can speed up the running of the software. 3. [Incorrect registration information

Linux Oops: Detailed explanation of what this error means Linux Oops: Detailed explanation of what this error means Mar 21, 2024 am 09:06 AM

LinuxOops: Detailed explanation of the meaning of this error, need specific code examples What is LinuxOops? In Linux systems, "Oops" refers to a situation where a serious error in the kernel causes the system to crash. Oops is actually a kernel crash mechanism that stops the system when a fatal error occurs and prints out relevant error information so that developers can diagnose and fix the problem. Oops usually occur in kernel space and have nothing to do with user space applications. When the kernel encounters

How to deal with the problem that Laravel page cannot display CSS correctly How to deal with the problem that Laravel page cannot display CSS correctly Mar 10, 2024 am 11:33 AM

"Methods to handle Laravel pages that cannot display CSS correctly, need specific code examples" When using the Laravel framework to develop web applications, sometimes you will encounter the problem that the page cannot display CSS styles correctly, which may cause the page to render abnormal styles. Affect user experience. This article will introduce some methods to deal with the failure of Laravel pages to display CSS correctly, and provide specific code examples to help developers solve this common problem. 1. Check the file path. First check the path of the CSS file.

How to implement page jump in 3 seconds: PHP Programming Guide How to implement page jump in 3 seconds: PHP Programming Guide Mar 25, 2024 am 10:42 AM

Title: Implementation method of page jump in 3 seconds: PHP Programming Guide In web development, page jump is a common operation. Generally, we use meta tags in HTML or JavaScript methods to jump to pages. However, in some specific cases, we need to perform page jumps on the server side. This article will introduce how to use PHP programming to implement a function that automatically jumps to a specified page within 3 seconds, and will also give specific code examples. The basic principle of page jump using PHP. PHP is a kind of

Streaming server throws error [FIXED] Streaming server throws error [FIXED] Mar 25, 2024 am 09:40 AM

Are you getting a streaming server throwing an error on your computer? Stremio is a cross-platform video streaming service that you can use to stream and watch movies, TV shows, live TV, and more. Some users have reported getting this error when trying to launch the application. Errors can occur under a variety of circumstances, including Internet and server issues. This error may also be encountered when using the web version of Stremio. Interference from antivirus software or firewalls can also cause errors to occur. Whatever the case, you can fix the problem with this guide. Streaming Server Throws Error While running Stremio application on Windows, you may encounter “Stremio Streaming Server threw error

See all articles