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


PHP IP::getClientIPfromXFF方法代码示例

本文整理汇总了PHP中IP::getClientIPfromXFF方法的典型用法代码示例。如果您正苦于以下问题:PHP IP::getClientIPfromXFF方法的具体用法?PHP IP::getClientIPfromXFF怎么用?PHP IP::getClientIPfromXFF使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IP的用法示例。


在下文中一共展示了IP::getClientIPfromXFF方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: CUChangesLine

 /**
  * @param Row $row
  * @param string $reason
  * @return a streamlined recent changes line with IP data
  */
 protected function CUChangesLine($row, $reason)
 {
     global $wgLang;
     static $cuTitle, $flagCache;
     $cuTitle = SpecialPage::getTitleFor('CheckUser');
     # Add date headers as needed
     $date = $wgLang->date(wfTimestamp(TS_MW, $row->cuc_timestamp), true, true);
     if (!isset($this->lastdate)) {
         $this->lastdate = $date;
         $line = "\n<h4>{$date}</h4>\n<ul class=\"special\">";
     } elseif ($date != $this->lastdate) {
         $line = "</ul>\n<h4>{$date}</h4>\n<ul class=\"special\">";
         $this->lastdate = $date;
     } else {
         $line = '';
     }
     $line .= '<li>';
     # Create diff/hist/page links
     $line .= $this->getLinksFromRow($row);
     # Show date
     $line .= ' . . ' . $wgLang->time(wfTimestamp(TS_MW, $row->cuc_timestamp), true, true) . ' . . ';
     # Userlinks
     $line .= $this->sk->userLink($row->cuc_user, $row->cuc_user_text);
     $line .= $this->sk->userToolLinks($row->cuc_user, $row->cuc_user_text);
     # Get block info
     if (isset($flagCache[$row->cuc_user_text])) {
         $flags = $flagCache[$row->cuc_user_text];
     } else {
         $user = User::newFromName($row->cuc_user_text, false);
         $ip = IP::isIPAddress($row->cuc_user_text) ? $row->cuc_user_text : '';
         $flags = $this->userBlockFlags($ip, $row->cuc_user, $user);
         $flagCache[$row->cuc_user_text] = $flags;
     }
     # Add any block information
     if (count($flags)) {
         $line .= ' ' . implode(' ', $flags);
     }
     # Action text, hackish ...
     if ($row->cuc_actiontext) {
         $line .= ' ' . $this->sk->formatComment($row->cuc_actiontext) . ' ';
     }
     # Comment
     $line .= $this->sk->commentBlock($row->cuc_comment);
     $line .= '<br />&#160; &#160; &#160; &#160; <small>';
     # IP
     $line .= ' <strong>IP</strong>: ' . $this->sk->makeKnownLinkObj($cuTitle, htmlspecialchars($row->cuc_ip), 'user=' . urlencode($row->cuc_ip) . '&reason=' . urlencode($reason));
     # XFF
     if ($row->cuc_xff != null) {
         # Flag our trusted proxies
         list($client, $trusted) = IP::getClientIPfromXFF($row->cuc_xff, $row->cuc_ip);
         $c = $trusted ? '#F0FFF0' : '#FFFFCC';
         $line .= '&#160;&#160;&#160;<span class="mw-checkuser-xff" style="background-color: ' . $c . '">' . '<strong>XFF</strong>: ';
         $line .= $this->sk->makeKnownLinkObj($cuTitle, htmlspecialchars($row->cuc_xff), 'user=' . urlencode($client) . '/xff&reason=' . urlencode($reason)) . '</span>';
     }
     # User agent
     $line .= '&#160;&#160;&#160;<span class="mw-checkuser-agent" style="color:#888;">' . htmlspecialchars($row->cuc_agent) . '</span>';
     $line .= "</small></li>\n";
     return $line;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:64,代码来源:CheckUser_body.php

示例2: onLoggableUserIPData

 /**
  * Handler for non-standard (edit/log) entries that need IP data
  *
  * @param $context IContextSource
  * @param $data Array
  * @return bool
  */
 protected static function onLoggableUserIPData(IContextSource $context, array $data)
 {
     $user = $context->getUser();
     $request = $context->getRequest();
     // Get IP address
     $ip = $request->getIP();
     // Get XFF header
     $xff = $request->getHeader('X-Forwarded-For');
     list($xff_ip, $isSquidOnly) = IP::getClientIPfromXFF($xff);
     // Get agent
     $agent = $request->getHeader('User-Agent');
     $dbw = wfGetDB(DB_MASTER);
     $cuc_id = $dbw->nextSequenceValue('cu_changes_cu_id_seq');
     $rcRow = array('cuc_id' => $cuc_id, 'cuc_page_id' => $data['pageid'], 'cuc_namespace' => $data['namespace'], 'cuc_title' => $data['title'], 'cuc_minor' => 0, 'cuc_user' => $user->getId(), 'cuc_user_text' => $user->getName(), 'cuc_actiontext' => $data['action'], 'cuc_comment' => $data['comment'], 'cuc_this_oldid' => 0, 'cuc_last_oldid' => 0, 'cuc_type' => RC_LOG, 'cuc_timestamp' => $dbw->timestamp($data['timestamp']), 'cuc_ip' => IP::sanitizeIP($ip), 'cuc_ip_hex' => $ip ? IP::toHex($ip) : null, 'cuc_xff' => !$isSquidOnly ? $xff : '', 'cuc_xff_hex' => $xff_ip && !$isSquidOnly ? IP::toHex($xff_ip) : null, 'cuc_agent' => $agent);
     $dbw->insert('cu_changes', $rcRow, __METHOD__);
     return true;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:24,代码来源:CheckUser.hooks.php

示例3: addConnectionLogEntry

 /**
  * @desc Add Chat log entry to "Special:Log" and Special:CheckUser;
  * otherwise to giving a chat moderator or banning this method isn't called via AJAX,
  * therefore we have to insert all information manually into DB table
  */
 public static function addConnectionLogEntry()
 {
     $wg = F::app()->wg;
     // record the IP of the connecting user.
     // use memcache so we order only one (user, ip) pair 3 min to avoid flooding the log
     $ip = $wg->Request->getIP();
     $memcKey = self::getUserIPMemcKey($wg->User->getID(), $ip);
     $entry = $wg->Memc->get($memcKey);
     if (empty($entry)) {
         $wg->Memc->set($memcKey, true, 60 * 3);
         $log = new LogPage('chatconnect', false, false);
         $log->addEntry('chatconnect', SpecialPage::getTitleFor('Chat'), '', [$ip], $wg->User);
         $xff = $wg->Request->getHeader(self::HTTP_HEADER_XFF);
         list($xff_ip, $isSquidOnly) = IP::getClientIPfromXFF($xff);
         $userAgent = $wg->Request->getHeader(self::HTTP_HEADER_USER_AGENT);
         $dbw = wfGetDB(DB_MASTER);
         $cuc_id = $dbw->nextSequenceValue('cu_changes_cu_id_seq');
         $rcRow = ['cuc_id' => $cuc_id, 'cuc_namespace' => NS_SPECIAL, 'cuc_title' => 'Chat', 'cuc_minor' => 0, 'cuc_user' => $wg->User->getID(), 'cuc_user_text' => $wg->User->getName(), 'cuc_actiontext' => wfMessage('chat-checkuser-join-action')->inContentLanguage()->text(), 'cuc_comment' => '', 'cuc_this_oldid' => 0, 'cuc_last_oldid' => 0, 'cuc_type' => CUC_TYPE_CHAT, 'cuc_timestamp' => $dbw->timestamp(), 'cuc_ip' => IP::sanitizeIP($ip), 'cuc_ip_hex' => $ip ? IP::toHex($ip) : null, 'cuc_xff' => !$isSquidOnly ? $xff : '', 'cuc_xff_hex' => $xff_ip && !$isSquidOnly ? IP::toHex($xff_ip) : null, 'cuc_agent' => $userAgent === false ? null : $userAgent];
         $dbw->insert('cu_changes', $rcRow, __METHOD__);
         $dbw->commit();
     }
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:27,代码来源:Chat.class.php


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