Trying to get a full URL without filename in PHP

后端 未结 7 1752
鱼传尺愫
鱼传尺愫 2020-12-31 01:32

I thought this would be simple but I can\'t seem to find a variable of $_SERVER array that has what I\'m looking for.

Let\'s say my url is http://

7条回答
  •  长情又很酷
    2020-12-31 02:22

    This worked perfectly for me and seems to be a very clean solution.

    $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
    $path = $protocol.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    

提交回复
热议问题