解析php中的ip地址 [英] parsing ip address in php
问题描述
我正在尝试创建一个页面,当用户在我的页面上显示用户的邮政编码时。
I am trying to create a page that shows the user their zip code when they are on my page.
(如果你们中的任何人熟悉GeoIP数据,那就是我正在使用的。)
(if any of you are familiar with GeoIP data, thats what I am using. )
我有将用户IP地址转换为IP号的转换,转换为:
I have a conversion that converts the users IP address into an IP number, that conversion is:
ipnum = 16777216 * w + 65536 * x + 256 * y + z
ipnum = 16777216*w + 65536*x + 256*y + z
其中wxyz是ip部分(000.000.000.000)
where w.x.y.z are the ip sections (000.000.000.000)
我的问题是,使用
$_SERVER['REMOTE_ADDR'];
我有办法划分用户IP地址并分配ip地址的部分变量?
is there a way for me to section the users ip address and assign the section of the ip address to variables?
例如:
usersip = 192.168.123.5
usersip = 192.168.123.5
w = 192;
x = 168;
y = 123;
z = 5;
w = 192; x = 168; y = 123; z = 5;
谢谢!
推荐答案
list($w, $x, $y, $z) = explode('.', $ip);
此外,您可以使用 ip2long
这篇关于解析php中的ip地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!