本文整理汇总了PHP中wfUtils::defaultGetIP方法的典型用法代码示例。如果您正苦于以下问题:PHP wfUtils::defaultGetIP方法的具体用法?PHP wfUtils::defaultGetIP怎么用?PHP wfUtils::defaultGetIP使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wfUtils
的用法示例。
在下文中一共展示了wfUtils::defaultGetIP方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getIP
public static function getIP()
{
//You can use the following examples to force Wordfence to think a visitor has a certain IP if you're testing. Remember to re-comment this out or you will break Wordfence badly.
//return '1.2.33.57';
//return '4.22.23.114';
//return self::makeRandomIP();
$howGet = wfConfig::get('howGetIPs', false);
if ($howGet) {
$IP = $_SERVER[$howGet];
if ($howGet == "HTTP_CF_CONNECTING_IP" && !self::isValidIP($IP)) {
$IP = $_SERVER['REMOTE_ADDR'];
}
} else {
$IP = wfUtils::defaultGetIP();
}
if (preg_match('/,/', $IP)) {
$parts = explode(',', $IP);
//Some users have "unknown,100.100.100.100" for example so we take the first thing that looks like an IP.
foreach ($parts as $part) {
if (preg_match('/(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)/', $part) && !self::isPrivateAddress($part)) {
$IP = trim($part);
break;
}
}
} else {
if (preg_match('/(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)\\s+(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)/', $IP)) {
$parts = explode(' ', $IP);
//Some users have "unknown 100.100.100.100" for example so we take the first thing that looks like an IP.
foreach ($parts as $part) {
if (preg_match('/(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)/', $part) && !self::isPrivateAddress($part)) {
$IP = trim($part);
break;
}
}
}
}
if (preg_match('/:\\d+$/', $IP)) {
$IP = preg_replace('/:\\d+$/', '', $IP);
}
if (self::isValidIP($IP)) {
if (wfConfig::get('IPGetFail', false)) {
if (self::isPrivateAddress($IP)) {
wordfence::status(1, 'error', "Wordfence is receiving IP addresses, but we received an internal IP of {$IP} so your config may still be incorrect.");
} else {
wordfence::status(1, 'error', "Wordfence is now receiving IP addresses correctly. We received {$IP} from a visitor.");
}
wfConfig::set('IPGetFail', '');
}
return $IP;
} else {
$xFor = "";
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$xFor = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
$msg = "Wordfence can't get the IP of clients and therefore can't operate. We received IP: {$IP}. X-Forwarded-For was: " . $xFor . " REMOTE_ADDR was: " . $_SERVER['REMOTE_ADDR'];
$possible = array();
foreach ($_SERVER as $key => $val) {
if (is_string($val) && preg_match('/^\\d+\\.\\d+\\.\\d+\\.\\d+/', $val) && strlen($val) < 255) {
if ($val != '127.0.0.1') {
$possible[$key] = $val;
}
}
}
if (sizeof($possible) > 0) {
$msg .= " Headers that may contain the client IP: ";
foreach ($possible as $key => $val) {
$msg .= "{$key} => {$val} ";
}
}
wordfence::status(1, 'error', $msg);
wfConfig::set('IPGetFail', 1);
return false;
}
}