Dane Posted November 13, 2007 Share Posted November 13, 2007 Hey guys, I cant seem to find or find out how to get the name of a subdomain within a website example. http://milk.monkeys.com How would i get the name of milk? Anyone know any websites to visit to create a function etc? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/77232-get-subdomain-name/ Share on other sites More sharing options...
kratsg Posted November 13, 2007 Share Posted November 13, 2007 Here's a function to get the current page URL (this I've used before on my scripts). I haven't tested it, but basically, get the full url, explode it around the ".", remove the http:// part of it and there you go. <?php function geturl() { $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") { $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; } else { $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; } return $pageURL; } $url = explode(".",geturl()); $subdomain = str_replace("http://","",$url[0]); ?> Link to comment https://forums.phpfreaks.com/topic/77232-get-subdomain-name/#findComment-391010 Share on other sites More sharing options...
Dane Posted November 13, 2007 Author Share Posted November 13, 2007 awesome, thanks a lot. Link to comment https://forums.phpfreaks.com/topic/77232-get-subdomain-name/#findComment-391013 Share on other sites More sharing options...
Dane Posted November 13, 2007 Author Share Posted November 13, 2007 on that script it works when i echo subdomain however i get Notice: Undefined index: HTTPS in /home/milk.php on line 4 line 4 being if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} Link to comment https://forums.phpfreaks.com/topic/77232-get-subdomain-name/#findComment-391034 Share on other sites More sharing options...
Dane Posted November 14, 2007 Author Share Posted November 14, 2007 ive changed $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";} $pageURL .= "://"; to $pageURL = 'http://'; and that seems to work fine. so im not sure how to change the $_SERVER bit Link to comment https://forums.phpfreaks.com/topic/77232-get-subdomain-name/#findComment-391239 Share on other sites More sharing options...
trq Posted November 14, 2007 Share Posted November 14, 2007 Should be.... $pageURL = 'http'; if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") { $pageURL .= "s"; } $pageURL .= "://"; Link to comment https://forums.phpfreaks.com/topic/77232-get-subdomain-name/#findComment-391290 Share on other sites More sharing options...
kratsg Posted November 14, 2007 Share Posted November 14, 2007 Thanks Thorpe, I shoulda realized that, pathetic mistake on my side :-( Link to comment https://forums.phpfreaks.com/topic/77232-get-subdomain-name/#findComment-391732 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.