[英]PHP - Get the request line from the headers
HTTP requests have headers, which can be obtained via getallheaders()
, but the first line of the request isn't a header. HTTP请求有标头,可以通过
getallheaders()
,但请求的第一行不是标头。 Instead it's the request line which looks like: 相反,它是请求行,看起来像:
GET /path/to/resource HTTP/1.1
or, with GET parameters, 或者,使用GET参数,
GET /path/to/resource?var1=val1&var2=val2 HTTP/1.1
How would I get this request line in PHP? 我如何在PHP中获取此请求行? Or would I need to rebuild it with $_SERVER vars?
或者我需要使用$ _SERVER变量重建它吗?
So for now (as per @mario's suggestion), I'm doing, 所以现在(根据@ mario的建议),我正在做,
$requestLine = $_SERVER['REQUEST_METHOD']
. ' ' . $_SERVER['REQUEST_URI']
. ' ' . $_SERVER['SERVER_PROTOCOL'];
which seems to work fine. 这似乎工作正常。
If anyone has an alternate solution that would get the exact string, I'll accept it instead, but otherwise this should suffice. 如果有人有一个可以得到确切字符串的替代解决方案,我会接受它,但否则这应该就足够了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.