美文网首页
PHP怎么判断当前是否为https协议

PHP怎么判断当前是否为https协议

作者: lookphp | 来源:发表于2016-12-28 15:38 被阅读569次
<?php
$urlinfo = parse_url($url);
if(!empty($urlinfo))
{
    $scheme = '';
    if (isset($urlinfo['scheme']) && $urlinfo['scheme']=='http')
    {
        $scheme = 'http://';
    }
    elseif (isset($urlinfo['scheme']) && $urlinfo['scheme']=='https')
    {
        $scheme = 'https://';
    }
    $urlname = $scheme.$urlinfo['host'];
    $urlport = $urlinfo['port'];
}

//注意 URL 一定要动态获取,不能hardcode
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";

$url = "$protocol.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]";

https默认是443但是什么端口都支持
转发的时候带个标志 或者 转发个非443的

我https,获取到的端口是80。
说明转发了

QQ图片20161228161427.png

相关文章

网友评论

      本文标题:PHP怎么判断当前是否为https协议

      本文链接:https://www.haomeiwen.com/subject/bdvyvttx.html