On this page
Validators
Host with Public IPv4 Address Validator
Laminas\Validator\HostWithPublicIPv4Address
allows you to validate that an IP address is not a reserved address such as 127.0.0.1, or that a hostname does not point to a known, reserved address.
Supported Options
This validator has no options
Basic Usage
$validator = new Laminas\Validator\HostWithPublicIPv4Address();
if ($validator->isValid('example.com')) {
// hostname appears to be valid
} else {
// hostname is invalid; print the reasons
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
$validator = new Laminas\Validator\HostWithPublicIPv4Address();
if ($validator->isValid('192.168.0.1')) {
// hostname appears to be valid
} else {
// hostname is invalid; print the reasons
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
Hostnames with Multiple Records
When validating a hostname as opposed to an IP address, if that hostname resolves to multiple IPv4 addresses and any of those addresses are private or reserved, then the validator will deem the hostname invalid.