Provides a simple way to check whether an address or domain is on a whitelist

1.2.0 2023-08-31 11:57 UTC

This package is auto-updated.

Last update: 2024-01-31 00:34:39 UTC


Run test suite Coverage Status Scrutinizer Code Quality


A modern and simple approach to validating IP addresses and domains against a whitelist. It supports both IPv4 and IPv6 addresses and CIDR subnets in addition to domain names and wild-card domains.


  • PHP 5.3 or newer


The Check::whitelist() method takes an array of definitions which will constitute the whitelist. The definitions can either be strings (which will be parsed to their respective objects) or objects.

The Check::check($value) method is used to check the specified value against the current whitelist. The method will return true if the value matches any of the definitions.

To create your own definition classes just extended Whitelist\Definition\Definition and implement Whitelist\Definition\IDefinition

Example usage:


$checker = new Whitelist\Check();

try {
		new Whitelist\Definition\Domain('vpn.work.com'),
catch (InvalidArgumentException $e) {
	// thrown when an invalid definition is encountered

$checker->check(''); // true
$checker->check(''); // false
$checker->check('2001:db8:100:934b::210:2'); // true
$checker->check('another.example.com'); // true


This library is licensed under the BSD 2-Clause License


This library depends on xrstf/ip-utils for the IP-related functionality. It also assumes that ip-utils's test cases are sufficient, which is why only trivial testing on these functions have been made for this library.