Created
July 2, 2025 08:26
-
-
Save tranchausky/4c287f22727828f8ea89817e0b0cdc46 to your computer and use it in GitHub Desktop.
php get domain at
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_absolute_root_url_my($with_scheme = true) | |
{ | |
$url = ''; | |
if ($with_scheme) | |
{ | |
$host = ''; | |
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { | |
$host = $_SERVER['HTTP_X_FORWARDED_HOST']; | |
} else if (isset($_SERVER['HTTP_HOST'])) { | |
$host = $_SERVER['HTTP_HOST']; | |
} | |
if (strpos($host, 'localhost') !== false) { | |
$url .= 'http://'; | |
} else { | |
$url .= 'https://'; | |
} | |
$url .= $host; | |
// Thêm cổng nếu cần | |
if ($host && strpos($host, 'localhost') !== false) { | |
$is_https = (strpos($url, 'https://') === 0); | |
if ((!$is_https && $_SERVER['SERVER_PORT'] != 80) || | |
($is_https && $_SERVER['SERVER_PORT'] != 443)) | |
{ | |
$url_port = ':' . $_SERVER['SERVER_PORT']; | |
if (strrchr($url, ':') != $url_port) { | |
$url .= $url_port; | |
} | |
} | |
} | |
} | |
$url .= cookie_path(); | |
return $url; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment