https://github.com/alexeevdv/yii2-ip-validator
[DEPRECATED] Use \yii\validators\IpValidator instead
https://github.com/alexeevdv/yii2-ip-validator
Last synced: about 2 months ago
JSON representation
[DEPRECATED] Use \yii\validators\IpValidator instead
- Host: GitHub
- URL: https://github.com/alexeevdv/yii2-ip-validator
- Owner: alexeevdv
- License: mit
- Created: 2015-09-22T15:48:21.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-22T19:36:40.000Z (over 9 years ago)
- Last Synced: 2025-02-04T22:27:26.935Z (4 months ago)
- Language: PHP
- Homepage: http://www.yiiframework.com/doc-2.0/yii-validators-ipvalidator.html
- Size: 145 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
yii2-ip-validator
=================Yii2 ip address validator. Can check that IP address is valid or in given range
## Installation
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
$ php composer.phar require alexeevdv/yii2-ip-validator "dev-master"
```or add
```
"alexeevdv/yii2-ip-validator": "dev-master"
```to the ```require``` section of your `composer.json` file.
## Usage
```php
public function rules() {
return [
//...
['ip', \alexeevdv\ip\Validator::className(), "range" => [
"192.168.1.1",
"10.62.15.0/24",
"109.232.0.0/16"
]],
//...
];
}// or
$validator = new \alexeevdv\ip\Validator([
"allowPrivate" => false,
"allowReserved" => false,
]);$validator->validate("127.0.0.1"); // false
```## Params
```php
/**
* Allow private ip addresses?
* 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16
*/
bool $allowPrivate = true;/**
* Allow reserved ip addresses?
* 0.0.0.0/8, 169.254.0.0/16, 192.0.2.0/24 and 224.0.0.0/4
*/
bool $allowReserved = true;/**
* Range of allowed ip addresses. Array of subnets and ip addresses.
*/
array $range = [];```