Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Add Comment
Please, Sign In to add comment