18 lines
529 B
PHP
18 lines
529 B
PHP
<?php
|
|
function validhostname($hostname,$pattmods='') {
|
|
preg_replace('/./u','.',$hostname,-1,$c);
|
|
(strlen($hostname)>$c) ? $multibyte=true : $multibyte=false;
|
|
if ($multibyte) $hostname=idn_to_ascii($hostname,IDNA_DEFAULT,INTL_IDNA_VARIANT_UTS46);
|
|
if (strlen($hostname)>253)
|
|
return false;
|
|
$labs=explode('.',$hostname);
|
|
foreach ($labs as $lab) {
|
|
$len=strlen($lab);
|
|
if ($len==0 || $len>63)
|
|
return false;
|
|
if (preg_match('#^[a-z0-9]([a-z0-9-]*[a-z0-9])?$#i'.$pattmods,$lab)!==1)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
?>
|