JS和PHP判断http还是https以及获得当前url的方法

$ecshop_cx_http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
echo $ecshop_cx_http_type . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>
js判断http请求还是https请求
var ecshop_cx_ishttps = 'https:' == document.location.protocol ? true: false;
if (ecshop_cx_ishttps)
{
    alert('https');
}
else
{
    alert('http');
}
php判断http请求还是https请求
/**
 * PHP判断当前协议是否为HTTPS
 */
function ecshop_cx_is_https()
{
    if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off')
    {
        return true;
    }
    elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' )
    {
        return true;
    }
    elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off')
    {
        return true;
    }
    return false;
}
调用方法
$http_type = $this->ecshop_cx_is_https();
if ($http_type)
{
    echo "是https";
}
else
{
    echo "是http";
}

本文原创地址:https://www.ecshop.cx/article-574.html
版权所有 © 转载时必须以链接形式注明出处!

觉得本文对您有用,想收藏下来!方法很简单:请点击-〉
我们一直坚持白天工作、晚上熬夜更新资源,付出了巨大的精力和时间,其中的辛酸难以言述。

实时购买动态 ×

conqueror会员 在 2019-12-06 购买了 ECShop插件网官方整站源码程序 全站加强SEO优化整合了实用功能