フォーム送信からの IP アドレス地理位置情報に基づいて位置情報を表示する Google マップを取得しようとしています。
以下の PHP コードは次のように機能します。テキスト ボックスに IP アドレスを入力すると、都市と国が表示されます。対応する都市の Google マップを自動的に取得する必要があります。
<html>
<body>
<?php
if( !defined('LOADED') )
die('You cannot access this file directly!');
function countryCityFromIP($ipAddr)
{
$url = "http://api.ipinfodb.com/v3/ip-city/?key=5cfaab6c5af420b7b0f88d289571b990763e37b66761b2f053246f9db07ca913&ip=$ipAddr&format=json";
$d = file_get_contents($url);
return json_decode($d , true);
}
if(isset($_REQUEST['submit'])){
$ip=countryCityFromIP($_REQUEST['ip']);
//print_r($ip);
$myString = "The City for the entered IP Address= ";
$myString2 = "The Country for the entered IP Address= ";
echo "<p style='text-align: center; font-size: 25px; font-family: georgia,palatino; color: #202020;'>".$myString.$ip['cityName']."</p>";
echo "<p style='text-align: center; font-size: 25px; font-family: georgia,palatino; color: #202020;'>".$myString2.$ip['countryName']."</p>";
}
?>
<form method="post">
<center><input type="text" name="ip" style="font-size:25pt;height:30px;width:400px"/></center>
<center><input type="submit" name="submit" value="Search IP Location" style="font-size:15pt;height:40px;width:200px"/></center>
</form>
</body>