Jump to content

GET Subdomain Name


Dane

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.