parsing ip address in php

半城伤御伤魂 提交于 2019-12-11 05:20:43

问题


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 (000.000.000.000)

My question is, using

$_SERVER['REMOTE_ADDR'];

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 = 192.168.123.5

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

Thanks!


回答1:


list($w, $x, $y, $z) = explode('.', $ip);

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



来源:https://stackoverflow.com/questions/4883413/parsing-ip-address-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!