function getIp() { static $realip = NULL; if ($realip !== NULL) { return $realip; } if (getenv( ‘HTTP_X_FORWARDED_FOR‘)) { $realip = getenv( ‘HTTP_X_FORWARDED_FOR‘); } elseif (getenv( ‘HTTP_CLIENT_IP‘)) { $realip = getenv( ‘HTTP_CLIENT_IP‘); } else { $realip = getenv( ‘REMOTE_ADDR‘); } preg_match("/[\d\.]{7,15}/", $realip, $onlineip); $realip = !empty($onlineip[0]) ? $onlineip[0] : ‘0.0.0.0‘; return $realip; }
$data[‘ip‘] = sprintf( ‘%u‘,ip2long(getIp()) );
ip2long ——把(IPv4)的字符串地址转换为int类型
sprintf—————把有符号的数字强制转换为无符号
反向 long2ip
时间: 2024-08-10 19:15:37