Wierd BUG with USER location

I have this code

<?php
    // Connect to the database
    $servername = "localhost";
    $username = "";
    $password = "";
    $dbname = "";

    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);

    // Check connection
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }


    // Get the user's IP address
    $user_r_ip = $_SERVER['REMOTE_ADDR'];

    function getUserIpAddr(){
        if(!empty($_SERVER['HTTP_CLIENT_IP'])){
            //ip from share internet
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
            //ip pass from proxy
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        }else{
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        return $ip;
    }



    //Get User Location details
    $user_ip = getUserIpAddr();
    $geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
    $country = $geo["geoplugin_countryName"];

    // Get the URL parameters
    $amount = $_COOKIE['amount'];
    $btc = $_COOKIE['btcadd'];


    if (isset($_COOKIE['btcadd']) && isset($_COOKIE['amount'])) {
        // Prepare the INSERT statement
        $stmt = mysqli_prepare($conn, "INSERT INTO btcs (btc, amount, country, ip) VALUES (?, ?, ?, ?)");

        // Bind the parameters
        mysqli_stmt_bind_param($stmt, "ssss", $btc, $amount, $country, $user_r_ip);

        // Execute the statement
        mysqli_stmt_execute($stmt);

        // Close the statement
        mysqli_stmt_close($stmt);

        // Close the connection
        mysqli_close($conn);
    }
    echo $country;
?>

and i have this code

<?php
    // Connect to the database
    $servername = "localhost";
    $username = "";
    $password = "";
    $dbname = "";

    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);

    // Check connection
    if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
    }

    // Get the user's IP address
    $user_r_ip = $_SERVER['REMOTE_ADDR'];

    function getUserIpAddr(){
        if(!empty($_SERVER['HTTP_CLIENT_IP'])){
            //ip from share internet
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        }elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
            //ip pass from proxy
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        }else{
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        return $ip;
    }

    // Get the URL parameters
    $btc = $_POST['btcadd'];
    $amount = $_POST['amount'];

    //Get User Location details
    $user_ip = getUserIpAddr();
    $geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?ip=$user_ip"));
    $country = $geo["geoplugin_countryName"];

    if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['btcadd']) && isset($_POST['amount'])) {
      // Prepare the INSERT statement
      $stmt = mysqli_prepare($conn, "INSERT INTO btcs (btc, amount, country, ip) VALUES (?, ?, ?, ?)");

      // Bind the parameters
      mysqli_stmt_bind_param($stmt, "ssss", $btc, $amount, $country, $user_r_ip);

      // Execute the statement
      if (!empty($btc)) {
        mysqli_stmt_execute($stmt);
        echo "btc address empty";
        //mysqli_stmt_close($stmt);
      } else {
        echo "<center>.</center>";
        mysqli_close($conn);
        $conn-exit();
      }
    }

?>

Why on the first code the user location is wrong? I am using COOKIES
And on the second code the user location is correct? i am using POST

And is there a way i get the correct location of the user on the first example? BTW the user IP's are correct in the both of the examples, only the country name is wrong on the first example