Convert IP to IP Number

$user_ip = explode(".", $_SERVER['REMOTE_ADDR']);

$w=$user_ip[0];
$x=$user_ip[1];
$y=$user_ip[2];
$z=$user_ip[3];

$ipnum = 16777216*$w + 65536*$x + 256*$y + $z;

//Beter Solution is to use the 'inet_aton' function in MySql
$the_ip = $_SERVER['REMOTE_ADDR'];
$country_query = "SELECT country_code2,country_name FROM webstats ".
"WHERE IP_FROM<=inet_aton('$the_ip') ".
"AND IP_TO>=inet_aton('$the_ip') ";