【问题标题】:How to get the protocol in php? [duplicate]如何在php中获取协议? [复制]
【发布时间】:2012-08-25 12:52:47
【问题描述】:

可能重复:
How To Find Out If You are Using HTTPS Without $_SERVER['HTTPS']
PHP Get Site URL Protocol - http vs https

如何在 php 中获取协议?

$_SERVER['SERVER_PROTOCOL']

向我展示了 HTTP/1.1,但有什么方法可以只回显 http 或 https?

【问题讨论】:

标签: php


【解决方案1】:
$protocol = current(explode('/',$_SERVER['SERVER_PROTOCOL']));

如果你真的只是想知道它是否启用了HTTPS,你可以使用$_SERVER['HTTPS']

【讨论】:

    【解决方案2】:
    list($protocol) = explode("/",$_SERVER['SERVER_PROTOCOL']);
    

    【讨论】:

      猜你喜欢
      • 2017-05-06
      • 2023-02-01
      • 1970-01-01
      • 2012-09-08
      • 2021-12-04
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 2011-05-29
      相关资源
      最近更新 更多