2011-02-03 07:22



I am trying to create a page that shows the user their zip code when they are on my page.

(if any of you are familiar with GeoIP data, thats what I am using. )

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

where w.x.y.z are the ip sections (

My question is, using


is there a way for me to section the users ip address and assign the section of the ip address to variables?

for example:

usersip =

w = 192; x = 168; y = 123; z = 5;


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dousi2013 dousi2013 10年前
    list($w, $x, $y, $z) = explode('.', $ip);

    Also, instead of math you could convert your ip to int with ip2long

    点赞 评论 复制链接分享