为什么 PHP 的“SERVER_PROTOCOL”即使在使用 https 时也会显示 HTTP/1.1?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16825243/
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-08-25 11:44:32  来源:igfitidea点击:

Why is PHP's "SERVER_PROTOCOL" showing HTTP/1.1 even when using https?

phphttps

提问by Don Rhummy

The addressbar shows "https://mywebsite.com" and it shows a lock icon (and clicking on that shows it's AES-256), but when I run the following code, it always prints "HTTP/1.1".

地址栏显示“ https://mywebsite.com”,并显示一个锁定图标(单击该图标显示它是 AES-256),但是当我运行以下代码时,它总是打印“HTTP/1.1”。

echo $_SERVER[ "SERVER_PROTOCOL" ];

Why doesn't this show https?

为什么这不显示https?

回答by Filippos Karapetis

SERVER_PROTOCOL has nothing to do with the security of your page, it reports if the connections used are HTTP 1.0 or HTTP 1.1 or HTTP 2.0:

SERVER_PROTOCOL 与页面的安全性无关,它报告使用的连接是 HTTP 1.0 或 HTTP 1.1 或 HTTP 2.0:

http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

HTTP/1.1 is a revision of the original HTTP (HTTP/1.0). In HTTP/1.0 a separate connection to the same server is made for every resource request. HTTP/1.1 can reuse a connection multiple times to download images, scripts, stylesheets et cetera after the page has been delivered. HTTP/1.1 communications therefore experience less latency as the establishment of TCP connections presents considerable overhead.

HTTP/1.1 是原始 HTTP (HTTP/1.0) 的修订版。在 HTTP/1.0 中,为每个资源请求建立到同一服务器的单独连接。HTTP/1.1 可以多次重用连接以在页面交付后下载图像、脚本、样式表等。因此,HTTP/1.1 通信的延迟更少,因为 TCP 连接的建立会带来相当大的开销。

While HTTP 2.0 is the next generation of HTTP that allows multiplexing of multiple HTTP 1.1 connections inside one HTTP 2.0 connection.

虽然 HTTP 2.0 是下一代 HTTP,它允许在一个 HTTP 2.0 连接内多路复用多个 HTTP 1.1 连接。

For your purposes, check if the HTTPS server variable is set:

出于您的目的,请检查是否设置了 HTTPS 服务器变量:

http://php.net/manual/en/reserved.variables.server.php

http://php.net/manual/en/reserved.variables.server.php

i.e. something like

即类似的东西

if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { ... }