Guest User

Untitled

a guest
Feb 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. function ign_getDomain() {
  2. $debug = true;
  3. $res = $_SERVER['HTTP_HOST'];
  4.  
  5. if (false === ip2long($res)) { # This is a normal domain string
  6. $d = explode('.', $_SERVER['HTTP_HOST']);
  7. // $d_copy keeps code simple
  8. $d_copy = $d;
  9. // Make sure the last 2 values look like TLDs (no more than 3 characters). Not bulletproof (.info? .mobi?), but simple.
  10. if ( (count($d) > 2) && (strlen(array_pop($d_copy)) < 4) && (strlen(array_pop($d_copy)) < 4) ) {
  11. $res = join('.', array_slice($d, -3, 3));
  12. }
  13. else {
  14. $res = join('.', array_slice($d, -2, 2));
  15. }
  16. $res .= '.'; # ensure canonical end-of-string
  17. }
  18. else {
  19. # This is an ip address. No action needed
  20. }
  21. if ($debug) dmp( $res );
  22. return $res;
  23. }
Add Comment
Please, Sign In to add comment