PHP how to get the base domain/url?

后端 未结 12 2134
渐次进展
渐次进展 2020-12-04 18:43
function url(){
    if(isset($_SERVER[\'HTTPS\'])){
        $protocol = ($_SERVER[\'HTTPS\'] && $_SERVER[\'HTTPS\'] != \"off\") ? \"https\" : \"http\";
    }         


        
12条回答
  •  隐瞒了意图╮
    2020-12-04 19:31

    Tenary Operator helps keep it short and simple.

    echo (isset($_SERVER['HTTPS']) ? 'http' : 'https' ). "://" . $_SERVER['SERVER_NAME']  ;
    

提交回复
热议问题