本文整理匯總了PHP中valid::ip方法的典型用法代碼示例。如果您正苦於以下問題:PHP valid::ip方法的具體用法?PHP valid::ip怎麽用?PHP valid::ip使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類valid
的用法示例。
在下文中一共展示了valid::ip方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ip_address
/**
* Fetch the IP Address.
*
* @return string
*/
public function ip_address()
{
if ($this->ip_address !== NULL) {
return $this->ip_address;
}
if ($ip = $this->server('HTTP_CLIENT_IP')) {
$this->ip_address = $ip;
} elseif ($ip = $this->server('REMOTE_ADDR')) {
$this->ip_address = $ip;
} elseif ($ip = $this->server('HTTP_X_FORWARDED_FOR')) {
$this->ip_address = $ip;
}
if ($comma = strrpos($this->ip_address, ',') !== FALSE) {
$this->ip_address = substr($this->ip_address, $comma + 1);
}
if (!valid::ip($this->ip_address)) {
// Use an empty IP
$this->ip_address = '0.0.0.0';
}
return $this->ip_address;
}
示例2: valid_ip_test
public function valid_ip_test()
{
$this->assert_true_strict(valid::ip('72.14.204.147'))->assert_true_strict(valid::ip('127.0.0.1'))->assert_false_strict(valid::ip('256.257.258.259'))->assert_false_strict(valid::ip('255.255.255.255'))->assert_false_strict(valid::ip('192.168.0.1'));
// invalid - private range
}
示例3: ip_address
/**
* Fetch the IP Address.
*
* @return string
*/
public function ip_address()
{
if ($this->ip_address !== NULL) {
return $this->ip_address;
}
// Server keys that could contain the client IP address
$keys = array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'REMOTE_ADDR');
foreach ($keys as $key) {
if ($ip = $this->server($key)) {
$this->ip_address = $ip;
// An IP address has been found
break;
}
}
if ($comma = strrpos($this->ip_address, ',') !== FALSE) {
$this->ip_address = substr($this->ip_address, $comma + 1);
}
if (!valid::ip($this->ip_address)) {
// Use an empty IP
$this->ip_address = '0.0.0.0';
}
return $this->ip_address;
}
示例4: ip
/**
* Tests the valid::ip() function.
* @dataProvider ip_provider
* @group core.helpers.valid.ip
* @test
*/
public function ip($input_ip, $allow_private, $expected_result)
{
$result = valid::ip($input_ip, FALSE, $allow_private);
$this->assertEquals($expected_result, $result);
}