可能重复:
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?
答案 0 :(得分:1)
$protocol = current(explode('/',$_SERVER['SERVER_PROTOCOL']));
如果您真的只是想知道HTTPS是否已启用,您可以使用$_SERVER['HTTPS']
。
答案 1 :(得分:0)
list($protocol) = explode("/",$_SERVER['SERVER_PROTOCOL']);