PHP how to get the base domain/url?

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


        
12条回答
  •  萌比男神i
    2020-12-04 19:36

    2 lines to solve it

    $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    $myDomain = preg_replace('/^www\./', '', parse_url($actual_link, PHP_URL_HOST));
    

提交回复
热议问题