What you're looking for is called "great circle calculation."
A simple Google search turns up this link:
http://greatcircle.locallink.net/
and this code:
Function greatcircle_fun($long1, $long2, $lat1, $lat2)
{
$distance= 1.15077 * 60.0 * rad2deg(
acos(sin(deg2rad($lat1))*sin(deg2rad($lat2))+
cos(deg2rad($lat1))*cos(deg2rad($lat2))*
cos(deg2rad($long2) - deg2rad($long1)))
);
return $distance;
}