IP address translation in the integer data and then saved to the database, this is a common practice, we convert the IP algorithm is Intip = 256*256*256*w + 256*256*x + 256*y + Z can be, the following to give you students to introduce specific examples.
"Principle of conversion": Assuming that IP is: w.x.y.z, the IP address to integer number is calculated as: Intip = 256*256*256*w + 256*256*x + 256*y + Z
"PHP Mutual transfer": Php conversion method is relatively simple, it built up two functions
int Ip2long (String $ip _address)//IP converted to integral type value
string Long2ip (String $proper _address)//integer value converted to IP "MySQL cross-turn": Compared to MSSQL, MySQL is a simpler way to convert, and it has two functions built into PHP as well.
IP to Integer type:
Select Inet_aton (IP address) integer value converted to IP
Select Inet_ntoa (integer value for IP)
An instance
Manual implementation of their own methods
function Ip2number ($IP) { $t = explode ('. ', $ip); $x = 0; for ($i = 0; $i < 4; $i + +) { $x = $x * + $t [$i]; } return $x; } function Number2ip ($num) { $t = $num; $a = array (); for ($i = 0; $i < 4; $i + +) { $x = $t%; if ($x < 0) $x + =; Array_unshift ($a, $x); $t = Intval ($t/256); } Return implode ('. ', $a); }
http://www.bkjia.com/PHPjc/631516.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631516. Htmltecharticleip address translation in the integer data is then saved to the database, this is a common practice, we convert the IP algorithm is Intip = 256*256*256*w + 256*256*x + 256*y + z can, the following to each ...