apache PHP 查询字符串限制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/507324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 17:13:04  来源:igfitidea点击:

PHP Query String Limit

phpapache

提问by Tim

I have PHP 5.1.6 (cli) installed and whenever the GET query string is more than 128 characters it fails with HTTP 406 Not Acceptable error. Any suggestions how I can fix this so can use more than 128 characters? POST is not an option.

我安装了 PHP 5.1.6 (cli),每当 GET 查询字符串超过 128 个字符时,它就会失败并显示 HTTP 406 Not Acceptable 错误。我有什么建议可以解决这个问题,以便可以使用超过 128 个字符?POST 不是一个选项。

The error is being returned by the server so don't think it's browser issue. And the reason I think it's PHP and not Apache is because it works fine with an HTML file.

服务器正在返回错误,因此不要认为这是浏览器问题。我认为它是 PHP 而不是 Apache 的原因是因为它可以很好地处理 HTML 文件。

GET /test.php?phptestof129characterstring-NEW-WOVEN-FENCE-PANELS-GARDEN_W0QQitemZ200303392512QQihZ010QQcategoryZ139954QQtcZphotoQQcmdZViewItem
HTTP/1.1
Host: *****
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: agent_name=Tim

HTTP/1.1 406 Not Acceptable
Date: Tue, 03 Feb 2009 12:05:33 GMT
Server: Apache/2.2.3 (Red Hat)
X-Powered-By: PHP/5.1.6
Content-Length: 0
Connection: close
Content-Type: text/html


GET /test.html?phptestof129characterstring-NEW-WOVEN-FENCE-PANELS-GARDEN_W0QQitemZ200303392512QQihZ010QQcategoryZ139954QQtcZphotoQQcmdZViewItem
HTTP/1.1
Host: *****
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: agent_name=Tim

HTTP/1.1 200 OK
Date: Tue, 03 Feb 2009 12:18:19 GMT
Server: Apache/2.2.3 (Red Hat)
Last-Modified: Fri, 19 Dec 2008 15:01:17 GMT
ETag: "156960d-221-94be8940"
Accept-Ranges: bytes
Content-Length: 545
Connection: close
Content-Type: text/html

采纳答案by Tim

Have found answer thanks to comment from Ben.

感谢 Ben 的评论找到了答案。

Although this generates 406 error: test.php?129+characters

虽然这会产生 406 错误:test.php?129+characters

This works fine: test.php?data=129+characters

这工作正常:test.php?data=129+characters

So my guess is that in the first instance PHP is attempting to use the 129 characters as name in $_GET array whereas the second example has only 4 characters for the name and the rest is assigned as value, so array must have 128 character limit for index name.

所以我的猜测是,在第一个实例中,PHP 试图在 $_GET 数组中使用 129 个字符作为名称,而第二个示例只有 4 个字符作为名称,其余的被分配为值,因此数组必须有 128 个字符的限制索引名称。

回答by Paul Dixon

Do you have mod_securityenabled on your webserver? It sounds like something it would do. If so, you may be able to disable locally inside your <VirtualHost>block or with an .htaccess file for v1.x

您的网络服务器上是否启用了mod_security?这听起来像是它会做的事情。如果是这样,您可以在<VirtualHost>块内本地禁用或使用 v1.x 的 .htaccess 文件禁用

<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>

Version 2.x has different configuration syntax:

2.x 版有不同的配置语法:

<IfModule mod_security2.c>
    SecRuleEngine Off
</IfModule>

That's a bit of a brute force approach, you may want to read the documentationto see how you might allow particular URIs to pass through. See also Handling False Positives and Creating Custom Rules

这是一种蛮力方法,您可能需要阅读文档以了解如何允许特定 URI 通过。另请参阅处理误报和创建自定义规则

回答by Micha? Tatarynowicz

As a work-around, you can try using Javascript to put the data in cookies. The cookies will be sent automatically with every GET request, and give you an extra 2KB of data space (if I'm not mistaken).

作为解决方法,您可以尝试使用 Javascript 将数据放入 cookie。cookie 将随每个 GET 请求自动发送,并为您提供额外的 2KB 数据空间(如果我没记错的话)。

This is very risky if you don't want to transmit that data with everyrequest, so generally speaking I would recommend against it.

如果您不想在每个请求中传输该数据,这是非常危险的,因此一般而言,我建议您不要这样做。

回答by Micha? Tatarynowicz

It's a long shot, but try adding:

这是一个长镜头,但尝试添加:

header('Content-Type: text/html');

to your server-side code. If that doesn't help, check your Apache configuration, maybe it's misconfigured so that PHP files can't emit text/html MIME type. If that doesn't help, how about setting up Apache so that .html files are treated as PHP and rename the target script to .html?

到您的服务器端代码。如果这没有帮助,请检查您的 Apache 配置,可能是配置错误,因此 PHP 文件无法发出 text/html MIME 类型。如果这没有帮助,那么如何设置 Apache 以便将 .html 文件视为 PHP 并将目标脚本重命名为 .html?

BTW, from http://www.checkupdown.com/status/E406.html:

顺便说一句,来自http://www.checkupdown.com/status/E406.html

A client (e.g. your Web browser or our CheckUpDown robot) can indicate to the Web server characteristics of the data it will accept back from the Web server. This is done using 'accept headers' of the following types:

  • Accept: The MIME types accepted by the client. For example, a browser may only accept back types of data (HTML files, GIF files etc.) it knows how to process.
  • Accept-Charset: The character sets accepted by the client.
  • Accept-Encoding: The data encoding accepted by the client e.g. the file formats it understands.
  • Accept-Language: The natural languages (English, German etc.) accepted by the client.
  • Accept-Ranges: Whether the client accepts ranges of bytes from the resource i.e. a portion of the resource.

If the Web server detects that the data it wants to return is not acceptable to the client, it returns a header containing the 406 error code.

客户端(例如您的 Web 浏览器或我们的 CheckUpDown 机器人)可以向 Web 服务器指示它将从 Web 服务器接收回的数据的特征。这是使用以下类型的“接受标头”完成的:

  • 接受:客户端接受的 MIME 类型。例如,浏览器可能只接受它知道如何处理的返回类型的数据(HTML 文件、GIF 文件等)。
  • Accept-Charset:客户端接受的字符集。
  • Accept-Encoding:客户端接受的数据编码,例如它理解的文件格式。
  • Accept-Language:客户端接受的自然语言(英语、德语等)。
  • Accept-Ranges:客户端是否接受来自资源的字节范围,即资源的一部分。

如果 Web 服务器检测到它要返回的数据不被客户端接受,它会返回一个包含 406 错误代码的标头。