First commit
This commit is contained in:
parent
09ac498c80
commit
72a23db0b8
1 changed files with 18 additions and 0 deletions
18
web/lib/validhostname.php
Normal file
18
web/lib/validhostname.php
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?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;
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue