First commit

This commit is contained in:
pezcurrel 2024-08-22 11:21:04 +02:00
parent 09ac498c80
commit 72a23db0b8

18
web/lib/validhostname.php Normal file
View 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;
}
?>