为什么PHP的“SERVER_PROTOCOL”是甚至在使用https时显示HTTP / 1.1? [英] Why is PHP's "SERVER_PROTOCOL" showing HTTP/1.1 even when using https?

查看:3460
本文介绍了为什么PHP的“SERVER_PROTOCOL”是甚至在使用https时显示HTTP / 1.1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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".

echo $_SERVER[ "SERVER_PROTOCOL" ];

为什么这不显示https?

Why doesn't this show https?

推荐答案

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

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:

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


HTTP / 1.1是原始HTTP(HTTP / 1.0)的修订版。在HTTP / 1.0中,为每个资源
请求提供与同一服务器的
单独连接。 HTTP / 1.1可以多次重复使用连接,以便在页面发送
后下载
图像,脚本,样式表等。因此,HTTP / 1.1通信的延迟减少了
,因为建立TCP连接会产生相当大的
开销。

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.

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

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

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

ie类似

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

这篇关于为什么PHP的“SERVER_PROTOCOL”是甚至在使用https时显示HTTP / 1.1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆