Saturday, November 13, 2010

IP to LongIP

 Converting standart IP format to long IP format.

function mbmIp2Long($ip) {
    $ex = explode(".", $ip);
    if (count($ex)!=4) return -1;
    list($a, $b, $c, $d) = $ex;
    $a = $a*16777216;
    $b = $b*65536;
    $c = $c*256;
    return $a+$b+$c+$d;
}

  1. echo mbmIp2Long(getenv("REMOTE_ADDR")); 

No comments:

Post a Comment