index.php
<!DOCTYPE html>
<html>
<body>
<form method="post" action="test.php">
Latitude1
:<br>
<input type="text" name="latitude1">
<br>
longitude1:<br>
<input type="text" name="longitude1">
<br>
Latitude2
:<br>
<input type="text" name="latitude2">
<br>
longitude2:<br>
<input type="text" name="longitude2">
<br>
<br>
<input type="submit" name="save" value="submit">
</form>
</body>
</html> 
 
test.php
<?php
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$lat1 = $_POST['latitude1'];
$lon1 = $_POST['longitude1'];
$lat2 = $_POST['latitude2'];
$lon2 = $_POST['longitude2'];
  $theta = $lon1 - $lon2;
  $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  $dist = acos($dist);
  $dist = rad2deg($dist);
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);
  if ($unit == "K") {
    return ($miles * 1.609344);
  } else if ($unit == "N") {
      return ($miles * 0.8684);
    } else {
        return $miles;
      }
}
echo distance("", "", "", "", "K") . " Kilometers<br>";
?>