User Information and Currency Convert API

Currency Convert to USD to IP Address Country Currency

<?php
$ip = $_SERVER["REMOTE_ADDR"];
$urlapi = "http://www.geoplugin.net/json.gp?ip=".$ip;

$response = file_get_contents($urlapi);

if ($response === FALSE) {
    die('Error occurred while fetching data.');
}
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
    die('Error decoding JSON data.');
}

$useragent = $_SERVER['HTTP_USER_AGENT']; 
$city = $data['geoplugin_city'];
$region = $data['geoplugin_region'];
$country = $data['geoplugin_countryName'];
$timezone = $data['geoplugin_timezone'];
$currencyCode = $data['geoplugin_currencyCode'];
$currencySymbol = $data['geoplugin_currencySymbol_UTF8'];
$currencyConverter = $data['geoplugin_currencyConverter'];
?>
<?php
date_default_timezone_set($timezone);
//$date_time = date("d.m.Y H:i:s");
$date_time = date("F j, Y, g:i a");
?>

<!DOCTYPE html>
<html>
<head>
    <title>Currency Convert</title>
</head>
<body>

<?php

// Output the user information
echo '<p><strong>User Information:</strong></p>';
echo '<p>Using (user agent): ' . htmlspecialchars($useragent, ENT_QUOTES, 'UTF-8') . '<br/>';
echo 'TimeZone: ' . htmlspecialchars($timezone, ENT_QUOTES, 'UTF-8') . '<br/>';
echo 'Date and Time: ' . htmlspecialchars($date_time, ENT_QUOTES, 'UTF-8') . '<br/>';
echo 'IP of the user: ' . htmlspecialchars($ip, ENT_QUOTES, 'UTF-8') . '<br/>';
echo 'City: ' . htmlspecialchars($city, ENT_QUOTES, 'UTF-8') . '<br/>';
echo 'State: ' . htmlspecialchars($region, ENT_QUOTES, 'UTF-8') . '<br/>';
echo 'Country: ' . htmlspecialchars($country, ENT_QUOTES, 'UTF-8') . '<br/>';
echo 'Currency Code: ' .  htmlspecialchars($currencyCode, ENT_QUOTES, 'UTF-8') . '<br/>';
echo 'Currency: ' . htmlspecialchars($currencySymbol, ENT_QUOTES, 'UTF-8') . '' . htmlspecialchars($currencyConverter, ENT_QUOTES, 'UTF-8') . '</p>';
?>

</body>
</html>

administrator

Leave a Reply

Your email address will not be published. Required fields are marked *