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

<?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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容