Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jason-gao/phpcomponent-whitelist
whiteList limit
https://github.com/jason-gao/phpcomponent-whitelist
Last synced: about 14 hours ago
JSON representation
whiteList limit
- Host: GitHub
- URL: https://github.com/jason-gao/phpcomponent-whitelist
- Owner: jason-gao
- Created: 2018-07-03T03:19:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-04T01:56:00.000Z (over 6 years ago)
- Last Synced: 2024-04-22T00:01:43.132Z (7 months ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# how to use?
* composer require jasong/phpcomponent-whitelist ~1.0```php
/**
* Setup the IP whitelist
*/
$whitelist = new Ip([
new \WhiteList\Network\Ip\Any(),
new \WhiteList\Network\Ip\Localhost(),
new \WhiteList\Network\Ip\Single(),
new \WhiteList\Network\Ip\Wildcard(),
new \WhiteList\Network\Ip\Range(),
new \WhiteList\Network\Ip\Cidr(),
]);//IP白名单配置
$white = [
'*',
'localhost',
'127.0.0.1',
'192.168.1.*',
'192.168.1.1-192.168.1.21',
'192.168.0.0/16',
];
$whitelist->buildWhitelist($white);
$obj = new xxx($whitelist);
$obj->xx($ip);class xxx{
private $whitelist;
public function __construct($whitelist){
$this->whitelist = $whitelist;
}
public function xx($ip){
//验证ip白名单
if (!$this->whitelist->isAllowed($ip)) {
return false;
}
//$next....
}
}```