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


PHP IP::canonicalize方法代码示例

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


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

示例1: wfGetIP

/** Work out the IP address based on various globals */
function wfGetIP()
{
    global $wgIP;
    # Return cached result
    if (!empty($wgIP)) {
        return $wgIP;
    }
    /* collect the originating ips */
    # Client connecting to this webserver
    if (isset($_SERVER['REMOTE_ADDR'])) {
        $ipchain = array(IP::canonicalize($_SERVER['REMOTE_ADDR']));
    } else {
        # Running on CLI?
        $ipchain = array('127.0.0.1');
    }
    $ip = $ipchain[0];
    # Append XFF on to $ipchain
    $forwardedFor = wfGetForwardedFor();
    if (isset($forwardedFor)) {
        $xff = array_map('trim', explode(',', $forwardedFor));
        $xff = array_reverse($xff);
        $ipchain = array_merge($ipchain, $xff);
    }
    # Step through XFF list and find the last address in the list which is a trusted server
    # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private)
    foreach ($ipchain as $i => $curIP) {
        $curIP = IP::canonicalize($curIP);
        if (wfIsTrustedProxy($curIP)) {
            if (isset($ipchain[$i + 1]) && IP::isPublic($ipchain[$i + 1])) {
                $ip = $ipchain[$i + 1];
            }
        } else {
            break;
        }
    }
    wfDebug("IP: {$ip}\n");
    $wgIP = $ip;
    return $ip;
}
开发者ID:negabaro,项目名称:alfresco,代码行数:40,代码来源:ProxyTools.php

示例2: getIP

 /**
  * Work out the IP address based on various globals
  * For trusted proxies, use the XFF client IP (first of the chain)
  *
  * @since 1.19
  *
  * @throws MWException
  * @return string
  */
 public function getIP()
 {
     global $wgUsePrivateIPs;
     # Return cached result
     if ($this->ip !== null) {
         return $this->ip;
     }
     # collect the originating ips
     $ip = $this->getRawIP();
     # Append XFF
     $forwardedFor = $this->getHeader('X-Forwarded-For');
     if ($forwardedFor !== false) {
         $ipchain = array_map('trim', explode(',', $forwardedFor));
         $ipchain = array_reverse($ipchain);
         if ($ip) {
             array_unshift($ipchain, $ip);
         }
         # Step through XFF list and find the last address in the list which is a trusted server
         # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private)
         foreach ($ipchain as $i => $curIP) {
             $curIP = IP::canonicalize($curIP);
             if (wfIsTrustedProxy($curIP)) {
                 if (isset($ipchain[$i + 1])) {
                     if ($wgUsePrivateIPs || IP::isPublic($ipchain[$i + 1])) {
                         $ip = $ipchain[$i + 1];
                     }
                 }
             } else {
                 break;
             }
         }
     }
     # Allow extensions to improve our guess
     wfRunHooks('GetIP', array(&$ip));
     if (!$ip) {
         throw new MWException("Unable to determine IP");
     }
     wfDebug("IP: {$ip}\n");
     $this->ip = $ip;
     return $ip;
 }
开发者ID:mangowi,项目名称:mediawiki,代码行数:50,代码来源:WebRequest.php

示例3: testIPCanonicalizeMappedAddress

 /**
  * @covers IP::canonicalize
  */
 public function testIPCanonicalizeMappedAddress()
 {
     $this->assertEquals('192.0.2.152', IP::canonicalize('::ffff:192.0.2.152'));
     $this->assertEquals('192.0.2.152', IP::canonicalize('::192.0.2.152'));
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:8,代码来源:IPTest.php

示例4: getIP

 /**
  * Work out the IP address based on various globals
  * For trusted proxies, use the XFF client IP (first of the chain)
  *
  * @since 1.19
  *
  * @throws MWException
  * @return string
  */
 public function getIP()
 {
     global $wgUsePrivateIPs;
     # Return cached result
     if ($this->ip !== null) {
         return $this->ip;
     }
     # collect the originating ips
     $ip = $this->getRawIP();
     if (!$ip) {
         throw new MWException('Unable to determine IP.');
     }
     # Append XFF
     $forwardedFor = $this->getHeader('X-Forwarded-For');
     if ($forwardedFor !== false) {
         $isConfigured = IP::isConfiguredProxy($ip);
         $ipchain = array_map('trim', explode(',', $forwardedFor));
         $ipchain = array_reverse($ipchain);
         array_unshift($ipchain, $ip);
         # Step through XFF list and find the last address in the list which is a
         # trusted server. Set $ip to the IP address given by that trusted server,
         # unless the address is not sensible (e.g. private). However, prefer private
         # IP addresses over proxy servers controlled by this site (more sensible).
         # Note that some XFF values might be "unknown" with Squid/Varnish.
         foreach ($ipchain as $i => $curIP) {
             $curIP = IP::sanitizeIP(IP::canonicalize($curIP));
             if (!$curIP || !isset($ipchain[$i + 1]) || $ipchain[$i + 1] === 'unknown' || !IP::isTrustedProxy($curIP)) {
                 break;
                 // IP is not valid/trusted or does not point to anything
             }
             if (IP::isPublic($ipchain[$i + 1]) || $wgUsePrivateIPs || IP::isConfiguredProxy($curIP)) {
                 // Follow the next IP according to the proxy
                 $nextIP = IP::canonicalize($ipchain[$i + 1]);
                 if (!$nextIP && $isConfigured) {
                     // We have not yet made it past CDN/proxy servers of this site,
                     // so either they are misconfigured or there is some IP spoofing.
                     throw new MWException("Invalid IP given in XFF '{$forwardedFor}'.");
                 }
                 $ip = $nextIP;
                 // keep traversing the chain
                 continue;
             }
             break;
         }
     }
     # Allow extensions to improve our guess
     Hooks::run('GetIP', array(&$ip));
     if (!$ip) {
         throw new MWException("Unable to determine IP.");
     }
     wfDebug("IP: {$ip}\n");
     $this->ip = $ip;
     return $ip;
 }
开发者ID:xfstudio,项目名称:mediawiki,代码行数:63,代码来源:WebRequest.php

示例5: wfGetIP

/**
 * Work out the IP address based on various globals
 * For trusted proxies, use the XFF client IP (first of the chain)
 * @return string
 */
function wfGetIP()
{
    global $wgUsePrivateIPs, $wgCommandLineMode;
    static $ip = false;
    # Return cached result
    if (!empty($ip)) {
        return $ip;
    }
    $ipchain = array();
    /* collect the originating ips */
    # Client connecting to this webserver
    if (isset($_SERVER['REMOTE_ADDR'])) {
        $ip = IP::canonicalize($_SERVER['REMOTE_ADDR']);
    } elseif ($wgCommandLineMode) {
        $ip = '127.0.0.1';
    }
    if ($ip) {
        $ipchain[] = $ip;
    }
    # Append XFF on to $ipchain
    $forwardedFor = wfGetForwardedFor();
    if (isset($forwardedFor)) {
        $xff = array_map('trim', explode(',', $forwardedFor));
        $xff = array_reverse($xff);
        $ipchain = array_merge($ipchain, $xff);
    }
    # Step through XFF list and find the last address in the list which is a trusted server
    # Set $ip to the IP address given by that trusted server, unless the address is not sensible (e.g. private)
    foreach ($ipchain as $i => $curIP) {
        $curIP = IP::canonicalize($curIP);
        if (wfIsTrustedProxy($curIP)) {
            if (isset($ipchain[$i + 1])) {
                if ($wgUsePrivateIPs || IP::isPublic($ipchain[$i + 1])) {
                    $ip = $ipchain[$i + 1];
                }
            }
        } else {
            break;
        }
    }
    # Allow extensions to improve our guess
    wfRunHooks('GetIP', array(&$ip));
    if (!$ip) {
        throw new MWException("Unable to determine IP");
    }
    wfDebug("IP: {$ip}\n");
    return $ip;
}
开发者ID:GodelDesign,项目名称:Godel,代码行数:53,代码来源:ProxyTools.php

示例6: getCurrUserName

 static function getCurrUserName()
 {
     global $wgUser, $wgSquidServers;
     global $wgUsePrivateIPs;
     if (self::$anon_forwarded_for === true && $wgUser->isAnon()) {
         /* collect the originating IPs
         			borrowed from ProxyTools::wfGetIP
         			bypass trusted proxies list check */
         # Client connecting to this webserver
         if (isset($_SERVER['REMOTE_ADDR'])) {
             $ipchain = array(IP::canonicalize($_SERVER['REMOTE_ADDR']));
         } else {
             # Running on CLI?
             $ipchain = array('127.0.0.1');
         }
         $ip = $ipchain[0];
         # Append XFF on to $ipchain
         $forwardedFor = wfGetForwardedFor();
         if (isset($forwardedFor)) {
             $xff = array_map('trim', explode(',', $forwardedFor));
             $xff = array_reverse($xff);
             $ipchain = array_merge($ipchain, $xff);
         }
         $username = "";
         foreach ($ipchain as $i => $curIP) {
             if ($wgUsePrivateIPs || IP::isPublic($curIP)) {
                 $username .= IP::canonicalize($curIP) . '/';
             }
         }
         if ($username != "") {
             # remove trailing slash
             $username = substr($username, 0, strlen($username) - 1);
         } else {
             $username .= IP::canonicalize($ipchain[0]);
         }
     } else {
         $username = $wgUser->getName();
     }
     return $username;
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:40,代码来源:qp_user.php

示例7: getIP

	/**
	 * Work out the IP address based on various globals
	 * For trusted proxies, use the XFF client IP (first of the chain)
	 *
	 * @since 1.19
	 *
	 * @throws MWException
	 * @return string
	 */
	public function getIP() {
		global $wgUsePrivateIPs;

		# Return cached result
		if ( $this->ip !== null ) {
			return $this->ip;
		}

		# collect the originating ips
		$ip = $this->getRawIP();

		# Append XFF
		$forwardedFor = $this->getHeader( 'X-Forwarded-For' );
		if ( $forwardedFor !== false ) {
			$ipchain = array_map( 'trim', explode( ',', $forwardedFor ) );
			$ipchain = array_reverse( $ipchain );
			if ( $ip ) {
				array_unshift( $ipchain, $ip );
			}

			# Step through XFF list and find the last address in the list which is a
			# trusted server. Set $ip to the IP address given by that trusted server,
			# unless the address is not sensible (e.g. private). However, prefer private
			# IP addresses over proxy servers controlled by this site (more sensible).
			foreach ( $ipchain as $i => $curIP ) {
				$curIP = IP::sanitizeIP( IP::canonicalize( $curIP ) );
				if ( wfIsTrustedProxy( $curIP ) && isset( $ipchain[$i + 1] ) ) {
					if ( wfIsConfiguredProxy( $curIP ) || // bug 48919; treat IP as sane
						IP::isPublic( $ipchain[$i + 1] ) ||
						$wgUsePrivateIPs
					) {
						$nextIP = IP::canonicalize( $ipchain[$i + 1] );
						if ( !$nextIP && wfIsConfiguredProxy( $ip ) ) {
							// We have not yet made it past CDN/proxy servers of this site,
							// so either they are misconfigured or there is some IP spoofing.
							throw new MWException( "Invalid IP given in XFF '$forwardedFor'." );
						}
						$ip = $nextIP;
						continue;
					}
				}
				break;
			}
		}

		# Allow extensions to improve our guess
		wfRunHooks( 'GetIP', array( &$ip ) );

		if ( !$ip ) {
			throw new MWException( "Unable to determine IP." );
		}

		wfDebug( "IP: $ip\n" );
		$this->ip = $ip;
		return $ip;
	}
开发者ID:nahoj,项目名称:mediawiki_ynh,代码行数:65,代码来源:WebRequest.php


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