时间:2021-07-01 10:21:17 帮助过:19人阅读
function get_http()
{
return isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off' ? 'https://' : 'http://';
}
function get_domain()
{
$protocol = get_http();
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
$host = $_SERVER['HTTP_X_FORWARDED_HOST'];
} elseif (isset($_SERVER['HTTP_HOST'])) {
$host = $_SERVER['HTTP_HOST'];
} else {
if (isset($_SERVER['SERVER_PORT'])) {
$port = ':' . $_SERVER['SERVER_PORT'];
if (':80' == $port && 'http://' == $protocol || ':443' == $port && 'https://' == $protocol) {
$port = '';
}
} else {
$port = '';
}
if (isset($_SERVER['SERVER_NAME'])) {
$host = $_SERVER['SERVER_NAME'] . $port;
} elseif (isset($_SERVER['SERVER_ADDR'])) {
$host = $_SERVER['SERVER_ADDR'] . $port;
}
}
return $protocol . $host;
}