$_SERVER['SERVER_NAME'] variable question
<p>How do you get actual host name, except for $_SERVER['SERVER_NAME']? Is there other way to get it ?  </p>

<p>I create a function which gets host name from PATH.  </p>

<p>I don't want to use $_SERVER['SERVER_NAME'] (You can do simple test via telnet) because it can be replaced by sending HTTP request (in headers) remotely via telnet or etc.</p>

<p>THis is done (will work if you have PATH like /vhosts/website.com/public_html):
<code></p>

<pre>
function getServerName() {
 $path = realpath(__FILE__);
 $url = array();
 preg_match_all("/\/[a-z0-9-]+(\.[a-z0-9-]+)+/i", $path, $url);
 // 4 is minimum requirement for the address (e.g: http://www.in.tv)
 if (strlen($url[0][0]) > 4) {
  $result = str_replace("/", "", $url[0][0]);
  return $result;
 }
 else
  return false;
}
</pre>

<p></code></p>

<p>Thanks!</p>
