当前位置:编程学习 > php >>

PHP获取当前完整网址加HTTP/HTTPS

一、PHP获取当前网址协议 完整方法
function get_http_type()
{
    $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
    return $http_type;

}


二、判断http还是https
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';

dump($http_type);


三、获取域名

dump($_SERVER['HTTP_HOST']);


四、获取地址
dump($http_type . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,