PHP [QUERY_STRING]在回车时被截断

时间:2013-05-20 21:35:16

标签: php apache

关于SO的第一个问题!

我在apache 2.2.22上运行PHP 5.3.10。我只是这样做:

<html>
<body>
<?php
file_put_contents('php://stderr', print_r($_SERVER, TRUE));
?>
</body>
</html>

Apache的error.log中的输出如下所示:

Array
(
[HTTP_HOST] => dns1
[PATH] => /usr/local/bin:/usr/bin:/bin
[SERVER_SIGNATURE] => <address>Apache/2.2.22 (Ubuntu) Server at dns1 Port 80</address>

[SERVER_SOFTWARE] => Apache/2.2.22 (Ubuntu)
[SERVER_NAME] => dns1
[SERVER_ADDR] => 192.168.2.6
[SERVER_PORT] => 80
[REMOTE_ADDR] => 98.210.76.128
[DOCUMENT_ROOT] => /var/www
[SERVER_ADMIN] => webmaster@localhost
[SCRIPT_FILENAME] => /var/www/rcv.php
[REMOTE_PORT] => 51164
[GATEWAY_INTERFACE] => CGI/1.1
R5 HTTP/1.0_PROTOCOL] => R5000
[REQUEST_METHOD] => GET
[QUERY_STRING] => UID=3333&DATA=R5000
[REQUEST_URI] => /rcv.php/?UID=3333&DATA=R5000
[SCRIPT_NAME] => /rcv.php
[PATH_INFO] => /
[PATH_TRANSLATED] => /var/www/index.html
[PHP_SELF] => /rcv.php/
[REQUEST_TIME] => 1369084575
)

传入的http请求的格式为:(来自apache的access.log的片段)

  

98.210.76.128 - - [20 / May / 2013:13:21:10 -0700]“GET /rcv.php/?UID=3333&DATA=R5000\rR5000\rR5000\rR5000\rR5000\rR5000\rR5000 \ rR5000 \ rR5000 \ rR5000 \ rR5000 \ rR5000 \ rR5000 \ rR5000 \ rR5000 \ rR5000 \ rR5000 \ rR5000 \ rR5000 \ rR5000

(这是一系列传感器读数。在这种情况下它们都是“R5000”。)

[QUERY_STRING][REQUEST_URI]似乎在第一次回车时被截断(\ r),导致我丢失其余的传感器读数。当我查看$ _GET值时,这已得到确认,DATA字段中只有一个传感器读数。

如何避免这种情况或改变这种行为?

2 个答案:

答案 0 :(得分:3)

您无法向GET请求发送回车。请尝试使用Post代替

答案 1 :(得分:3)

参数及其值应该是urlnecoded,因此在您的网址中使用\r

代替%0D