当前位置: 首页>>代码示例>>PHP>>正文


PHP wfUtils::defaultGetIP方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:mariuskarma,项目名称:wp,代码行数:74,代码来源:wfUtils.php


注:本文中的wfUtils::defaultGetIP方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。