Get Root Domain from Referrer

@param string $Referrer
@return boolean|string   false: no dns, string: Domain
965653
protected static function getReferrerDns($Referrer = false)
    {
        if ($Referrer === false)
        {
            $http_referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'unknown' ;
        }
        else
        {
            $http_referrer = $Referrer;
        }
        //nur den host Anteil prüfen
        $referrer_DNS = parse_url( $http_referrer, PHP_URL_HOST );
        if ($referrer_DNS === NULL)
        {
            //try this...
            $referrer_DNS = @parse_url( 'http://'.$http_referrer, PHP_URL_HOST );
            if ($referrer_DNS === NULL ||
                $referrer_DNS === false)
            {
                //wtf...
                return false;
            }
        }
        return $referrer_DNS;
    }
916515
public static function WebRoot($WithDomain = FALSE) {
      $WebRoot = Gdn::Request()->WebRoot();

      if ($WithDomain)
         $Result = Gdn::Request()->Domain().'/'.$WebRoot;
      else
         $Result = $WebRoot;

      return $Result;
   }
629761
public static function getRootDomain($url)
    {
        $host = $domain = self::getHostname($url);
        $root = false;

        if (($dotsCount = substr_count($host, '.')) > 0) {
            $last = $domain;
            while ($dotsCount > -1) {
                if (self::isHostInSuffixList($domain)) {
                    $root = $last;
                    break;
                }
                $last = trim($domain, '.');
                $domain = substr($last, strpos($last, '.'));
                $dotsCount = $dotsCount - 1;
            }
        }

        return $root;
    }
963062
public function getReferer($default = null)
    {
        if (!$current = $this->requestStack->getCurrentRequest()) {
            return $default;
        }

        $referer = $current->headers->get('referer');

        if ($referer === $current->getUri()) {
            return $default;
        }

        return $referer;
    }
269182
public static function getDomain()
    {
        $domain=self::getAppDomain();
        $arr=explode(".", $domain);
        $c=count($arr);
        $root="";
        if($c>0)$root=$arr[$c-1];
        if($c>1)$root=$arr[$c-2].".".$root;
        if(strpos($root, ":")){
            $root=substr($root, 0,strpos($root, ":"));
        }
        return $root;
    }
1136805
public function prepareGet($url, $callback = null, $referer = '') {
        if (!$this->inUsed) {
            $this->inUsed = true;
            $options      = [
                CURLOPT_URL         => $url,
                CURLOPT_POST        => 0,
                CURLOPT_AUTOREFERER => 1,
                CURLOPT_POSTFIELDS  => null,
                CURLOPT_REFERER     => $referer,
                CURLOPT_HTTPGET     => 1
            ];
            curl_setopt_array($this->ch, $options);
            $this->mcallback = $callback;

            return $this;
        }

        return null;
    }
1155635
def top_referrers(self, domain_only=True):
        
        referrer = self._referrer_clause(domain_only)
        return (self.get_query()
                .select(referrer, fn.Count(PageView.id))
                .group_by(referrer)
                .order_by(fn.Count(PageView.id).desc())
                .tuples())
576180
public function getDomain($controller)
    {
        $origin = parse_url($controller->getRequest()->getHeader('Referer'));
        $uri = $controller->getRequest()->getUri();
        $domainId = $uri->getHost();

        if (isset($origin['query'])) {
            parse_str($origin['query'], $query);
            $domainId = $query['xdm_e'];
        }

        $domain = $this->getDomainMapper()->findOneBy(array(
            'domain' => $domainId
        ));

        return $domain;
    }
1316163
public function domain($domain = null) {
        if (!is_null($domain)) {
            $this->domain = $domain;
            return $this;
        } elseif (!$this->domain) {
            $this->domain = $this->scheme() . '://' . $this->host();
        }
        return $this->domain;
    }
64112
def is_internal_request(self, domain, referer):
        
        # Different subdomains are treated as different domains.
        return bool(re.match("^https?://%s/" % re.escape(domain), referer))
849005
private function computeReferrerChanges($mapping, $referrer)
    {
        $targetClass = $this->dm->getClassMetadata(get_class($referrer));
        $state = $this->getDocumentState($referrer);

        switch ($state) {
            case self::STATE_NEW:
                if (!($mapping['cascade'] & ClassMetadata::CASCADE_PERSIST)) {
                    throw CascadeException::newDocumentFound(self::objToStr($referrer));
                }
                $this->persistNew($targetClass, $referrer);
                $this->computeChangeSet($targetClass, $referrer);
                break;
            case self::STATE_DETACHED:
                throw new InvalidArgumentException('A detached document was found through a referrer during cascading a persist operation: '.self::objToStr($referrer, $this->dm));
        }
    }
599130
public function referer($referer) {

		if(false === is_string($referer)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($referer)), E_USER_ERROR);
		}

		$this -> options[CURLOPT_REFERER] = $referer;

		return $this;
	}
1109975
public static function domain($str='', bool $unicode=false) {
		ref\sanitize::domain($str, $unicode);
		return $str;
	}
325856
public function referer($default = null, $local = false) {
		if ($ref = $this->env('HTTP_REFERER')) {
			if (!$local) {
				return $ref;
			}
			$url = parse_url($ref) + ['path' => ''];
			if (empty($url['host']) || $url['host'] === $this->env('HTTP_HOST')) {
				$ref = $url['path'];
				if (!empty($url['query'])) {
					$ref .= '?' . $url['query'];
				}
				if (!empty($url['fragment'])) {
					$ref .= '#' . $url['fragment'];
				}
				return $ref;
			}
		}
		return ($default !== null) ? $default : '/';
	}
380900
public function setReferrer($referrer = '')
    {
        $this->referrer = $referrer;
        $this->debug->info(__FUNCTION__, 'setReferrer: ', $this->referrer);

        return $this;
    }
892133
protected function _getDomains($str)
    {
        $domains = array();
        $str = trim($str);
        if (strlen($str)) {
            $str = array_map('trim', preg_split("%[^a-z\-\d\.]+%", strtolower($str)));
            foreach ($str as $domain) {
                if (strlen($domain)) {
                    $domains[] = $domain;
                }
            }
        }
        return $domains;
    }
340099
public function getReferer()
    {
        $referer = null;

        if (array_key_exists(self::REFERER_KEY, $this->serverData)) {
            $referer = $this->serverData[self::REFERER_KEY];
        }

        return $referer;
    }