php - 为什么要修改 REQUEST_URI?

标签 php

当我在 req.php 中运行以下代码时:

<?php
  echo("Request:\n");
  print_r($_SERVER['REQUEST_URI']);
?>

要求:

curl "http://localhost/req.php/postcode/14482/city/./country/de/"

我收到这样的回复:

Request:
/req.php/postcode/14482/city/country/de/

当我在/city 之后使用两个点时:

Request:
/req.php/postcode/14482/country/de/

在/city 之后加上三个点:

Request:
/req.php/postcode/14482/city/.../country/de/

为什么 REQUEST_URI 被修改而不是原封不动地传递?

编辑:cURL 似乎正在编辑 REQUEST_URI - cURL php 库中是否有任何设置来禁用此行为?

最佳答案

Why is the REQUEST_URI being modified instead of passed thru untouched ?

事实并非如此。 URL 的更改由 cURL 在它到达服务器附近的任何地方之前进行。 ./ 永远不会出现在发送到服务器的请求中。

./ 表示“当前路径段”,因此它是多余的。客户端 (cURL) 在发出请求之前对其进行规范化。

您可以通过将对使用 curl 的请求的响应与手动构造 HTTP 请求时的响应进行比较来了解这一点。

手动构造请求

%  telnet localhost 7007
Trying ::1...
Connected to localhost.
Escape character is '^]'.
GET /index.php/req.php/postcode/14482/city/./country/de/

HTTP/0.9 200 OK
Date: Wed, 04 Apr 2018 07:53:23 +0000
Connection: close
X-Powered-By: PHP/7.1.7
Content-type: text/html; charset=UTF-8

Request:
/index.php/req.php/postcode/14482/city/./country/de/
Connection closed by foreign host.

curl

%  curl http://localhost:7007/index.php/req.php/postcode/14482/city/./country/de/
Request:
/index.php/req.php/postcode/14482/city/country/de/

关于php - 为什么要修改 REQUEST_URI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49645538/

相关文章:

javascript - 如何在 jquery/javascript 中的黑白表单标签中选择带有名称的隐藏输入标签

php - 使用带有一系列 id 的 where 语句

php - 如何根据表中的特定字段回显变量?

php - 奇怪的 mysql 语法错误,打开和关闭

php - 这是获取日期时间的错误方法吗?

php - 是否可以自动提交php表单

php - 使用 php 从字符串中查找 url

php - 使用 php 在 strip 中创建托管帐户时如何提供外部帐户参数?

php - mySql自定义选择和显示

php - 邮件中的卢比符号