Created
September 17, 2008 15:18
-
-
Save netcarver/11245 to your computer and use it in GitHub Desktop.
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
function ign_getDomain() { | |
$debug = true; | |
$res = $_SERVER['HTTP_HOST']; | |
if (false === ip2long($res)) { # This is a normal domain string | |
$d = explode('.', $_SERVER['HTTP_HOST']); | |
// $d_copy keeps code simple | |
$d_copy = $d; | |
// Make sure the last 2 values look like TLDs (no more than 3 characters). Not bulletproof (.info? .mobi?), but simple. | |
if ( (count($d) > 2) && (strlen(array_pop($d_copy)) < 4) && (strlen(array_pop($d_copy)) < 4) ) { | |
$res = join('.', array_slice($d, -3, 3)); | |
} | |
else { | |
$res = join('.', array_slice($d, -2, 2)); | |
} | |
$res .= '.'; # ensure canonical end-of-string | |
} | |
else { | |
# This is an ip address. No action needed | |
} | |
if ($debug) dmp( $res ); | |
return $res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment