2009-02-03 50 views
3

我安裝了PHP 5.1.6(cli),並且每當GET查詢字符串超過128個字符時,將以HTTP 406 Not Acceptable錯誤失敗。任何建議如何解決這個問題可以使用超過128個字符? POST不是一個選項。PHP查詢字符串限制

錯誤是由服務器返回,所以不要認爲它是瀏覽器問題。 而我認爲它是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 
+0

如果使用&和=來分隔查詢字符串,它會起作用嗎? – Ben 2009-02-03 14:47:47

回答

0

已經找到答案多虧了本評論。

雖然這會產生406錯誤: test.php的129 +字符

這工作得很好: test.php的數據= 129個+字符

所以我的猜測是,在一審PHP試圖在$ _GET數組中使用129個字符作爲名稱,而第二個示例只有4個字符作爲名稱,其餘的作爲值分配,因此數組必須具有索引名稱的128個字符限制。

2

你有mod_security您的網絡服務器啓用?這聽起來像是它會做的。如果是的話,你可以到你的<VirtualHost>塊內部或與1.x版.htaccess文件在本地禁用

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

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

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

這是一個有點您可能想要閱讀documentation以瞭解如何允許特定的URI通過。另請參閱Handling False Positives and Creating Custom Rules

+0

它看起來確實已啓用mod_security,但將「SecFilterEngine關閉」和「SecFilterScanPOST關閉」添加到htaccess文件中並沒有什麼區別。 – Tim 2009-02-03 14:55:33

+0

你有什麼版本 - 已經修改我的帖子爲v2.x – 2009-02-03 15:02:54

+0

剛剛嘗試過你對v2的建議,但那也沒有完成。 這是什麼在httpd.conf中: LoadModule security_module /usr/lib/httpd/modules/mod_security.so 不知道我怎麼能告訴它是什麼版本? – Tim 2009-02-03 15:06:42

0

作爲解決方法,您可以嘗試使用Javascript將數據放入Cookie中。 Cookie將在每次GET請求時自動發送,併爲您提供額外的2KB數據空間(如果我沒有弄錯的話)。

如果你不想用請求傳輸數據,這是非常危險的,所以一般來說我會推薦它。

0

這是一個長鏡頭,但嘗試添加:

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

到你的服務器端代碼。如果這沒有幫助,請檢查您的Apache配置,可能是配置錯誤,以便PHP文件不能發出文本/ html的MIME類型。如果這沒有幫助,那麼如何設置Apache以便將.html文件視爲PHP並將目標腳本重命名爲.html?

BTW,從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.