Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

<?

php
//

$ipaddress = getenv("REMOTE_ADDR") ;
//Echo "Your IP Address is " . $ipaddress;

$servername = "localhost";
$username = "id20189993_dbusername";
$password = "5SP&kqq3ZYD(l#>H";
$dbname = "id20189993_modb";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$theip = $ipaddress;
//http://ip-api.com/php/{query}?fields=country,city,lat,lon,isp
$websiteapi= 'http://ip-api.com/json/';
$thefields ='?fields=country,city,lat,lon,query';
//echo $websiteapi . "" . $ipaddress . $thefields;
$entityBody = file_get_contents($websiteapi . "" . $ipaddress . $thefields);

json_encode($entityBody);
$sql = "INSERT INTO IPs (IP,LatitudeLongitude)
VALUES ('$ipaddress','$entityBody')";

if ($conn->query($sql) === TRUE) {


//echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();

//

?>

You might also like