选择语言 :

 Core_IpSource::get

获取IP地址

string Core_IpSource::get( [ string $ip = null ] )

参数列表

参数 类型 描述 默认值
$ip string 不传则为访客IP null
返回值
  • string
File: ./core/classes/ipsource.class.php
public static function get($ip = null)
{
    $ip or $ip = HttpIO::IP;
    if ( $ip == '127.0.0.1' || $ip == '0.0.0.0' ) return 'Local IP';
    $return = '';

    if ( preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $ip) )
    {

        $iparray = explode('.', $ip);

        if ( $iparray[0] == 10 || $iparray[0] == 127 || ($iparray[0] == 192 && $iparray[1] == 168) || ($iparray[0] == 172 && ($iparray[1] >= 16 && $iparray[1] <= 31)) )
        {
            $return = 'LAN';
        }
        elseif ( $iparray[0] > 255 || $iparray[1] > 255 || $iparray[2] > 255 || $iparray[3] > 255 )
        {
            $return = 'Invalid IP Address';
        }
        else
        {
            if ( true==($tinyipfile = Core::find_file('data','tinyipdata','dat')) )
            {
                $return = IpSource::_convertip_tiny($ip, $tinyipfile);
            }
            elseif ( true==($fullipfile = Core::find_file('data','wry','dat')) )
            {
                $return = IpSource::_convertip_full($ip, $fullipfile);
            }
        }
    }

 return $return;
}