NewsNewsFeaturesDownloadsDevelopmentSupportForumDocumentsAbout Us

IpRangeRule 類別 參考文件
[Validator_Rules]

類別IpRangeRule的繼承圖:

Rule Validation Object 全部成員列表

公開方法(Public Methods)

 IpRangeRule ($range)
 setRange ($range)
 getRange ()
 validate ($value)

公開屬性

 $_range

詳細描述

This rule returns true if the given IP address is within a certain range. Use the constructor or the setRange() method for setting the right range. The range should be given in a submask format, so for example 1.2.3.4 would be within the range 1.2.3.255

It will set the error flag ERROR_RULE_IP_NOT_IN_RANGE error if the address is not in the given range.

定義在 iprangerule.class.php 檔案之第 17 行.


建構子與解構子說明文件

IpRangeRule::IpRangeRule range  ) 
 

Initializes the rule with the given range

參數:
range The range.

定義在 iprangerule.class.php 檔案之第 26 行.

參考 Rule::Rule().

00027         {
00028             $this->Rule();
00029             $this->_range = $range;
00030         }


函式成員說明文件

IpRangeRule::getRange  ) 
 

Returns the current range being used for the calculations

傳回值:
A string representing the range

定義在 iprangerule.class.php 檔案之第 47 行.

00048         {
00049             return $this->_range;
00050         }

IpRangeRule::setRange range  ) 
 

Sets a different range than the one given in the constructor

參數:
range the new range

定義在 iprangerule.class.php 檔案之第 37 行.

00038         {
00039             $this->_range = $range;
00040         }

IpRangeRule::validate value  ) 
 

Returns true if the address is within the given range or false otherwise. It will also set the error ERROR_RULE_IP_NOT_IN_RANGE

參數:
value The IP address to validate
傳回值:
True if within range or false otherwise

依據Rule重新實作.

定義在 iprangerule.class.php 檔案之第 59 行.

參考 Validation::_setError().

00060         {
00061             $counter = 0;
00062             $range   = explode("/", $this->_range);
00063 
00064             if ($range[1] < 32)
00065             {
00066                 $maskBits  = $range[1];
00067                 $hostBits  = 32 - $maskBits;
00068                 $hostCount = pow(2, $hostBits) - 1;
00069                 $ipStart   = ip2long($range[0]);
00070                 $ipEnd     = $ipStart + $hostCount;
00071 
00072                 if ((ip2long($value) > $ipStart) && (ip2long($value) < $ipEnd))
00073                 {
00074                     $this->_setError(false);
00075                     return true;
00076                 }
00077             }
00078             elseif (ip2long($value) == ip2long($range[0]))
00079             {
00080                 $this->_setError(false);
00081                 return true;
00082             }
00083 
00084             $this->_setError(ERROR_RULE_IP_NOT_IN_RANGE);
00085             return false;
00086         }


資料成員說明文件

IpRangeRule::$_range
 

定義在 iprangerule.class.php 檔案之第 19 行.


此類別(class) 文件是由下列檔案中產生: