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. Quote Link to comment 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]); ?> Quote Link to comment Share on other sites More sharing options...
Dane Posted November 13, 2007 Author Share Posted November 13, 2007 awesome, thanks a lot. Quote Link to comment 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";} Quote Link to comment 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 Quote Link to comment 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 .= "://"; Quote Link to comment 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 :-( Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.