本文整理汇总了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);
}