/** * Checks if the given hostname is valid. * * @param $hostname * @param bool $allowIp Allow IP Addresses * @param bool $allowWildcard Allow Wildcard names * @param bool $allowLocal Allow local Addresses * @param bool $looseCheck Switches checking off checks only if * given variable is not empty * * @return bool */ public function _checkHostname($hostname, $allowIp = true, $allowWildcard = false, $allowLocal = true, $looseCheck = false) { if ('.' == substr($hostname, -1)) { return false; } if ($looseCheck === true) { return 0 == strlen(trim($hostname)) ? false : true; } $n = new Hostname(); $n->setAllow(Hostname::ALLOW_DNS); if ($allowIp) { $n->setAllow(Hostname::ALLOW_IP | Hostname::ALLOW_DNS); } if ($allowWildcard) { $hostname = str_replace('*.', 'bogus', $hostname); } if (!filter_var($hostname, FILTER_VALIDATE_IP)) { $exp = explode('.', $hostname); if (1 == count($exp)) { if (!$allowLocal) { return false; } $hostname = $hostname . '.syseleven.de'; } } if (!$n->isValid($hostname)) { return false; } return true; }