<?php
$ip = $_SERVER["REMOTE_ADDR"];
//echo $ip;

$curl = curl_init("http://www.geoplugin.net/json.gp?ip=" . $ip);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$res =  curl_exec($curl);

$loc = json_decode($res);
//echo $loc;

$city = $loc->geoplugin_city;
$state = $loc->geoplugin_regionName;
$country = $loc->geoplugin_countryName;

echo $state;
echo $city;
echo $country;

$user = "educateb_bof-engla";
$pass = "bof-engla.com";
$dbname = "educateb_bof-engla";

$conn = mysqli_connect("localhost", $user, $pass, $dbname);
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$date = date("m-d-Y H:i:s");
//$sql5 = "INSERT INTO loginh (username,time,location) VALUES('Daniel','ede','ede')";

$sql5 = "INSERT INTO loginh (username,time,location) VALUES('Daniel','$date','$country')";

mysqli_query($conn, $sql5);

?>