0

APIを使用してIPアドレスのIP情報を取得するスクリプトがあります。訪問者が入力すると、訪問者のIPに関するデフォルト情報のみが表示されますが、フォームにIPを入力して検索をクリックすることで、訪問者が特定のIPアドレスを検索できるようにフォームを作成したいと思います。

作り方がわかりません。あなたの助けが必要です。ありがとうございます。

index.php

<?php

require_once('ipapi.class.php');

$ip = $_REQUEST['REMOTE_ADDR']; // the IP address to query
$query = IPAPI::query("$rip");

echo "\t IP Information: " .$rip. "<br />";
echo "\t ISP: " .$query->isp . "<br />";
echo "\t Organization: " .$query->org . "<br />";
echo "\t City: " .$query->city . "<br />";
echo "\t Region: " .$query->regionName . "<br />";
echo "\t Country: " .$query->country . "<br />"; 

?>
4

1 に答える 1

0

そのための html フォームが必要です。index.php は次のようになります。

<?php

require_once('ipapi.class.php');

if(isset($_GET['ip']))
    $rip = $_GET['ip'];
else
    $rip = $_REQUEST['REMOTE_ADDR']; // the IP address to query

$query = IPAPI::query("$rip");

echo "\t IP Information: " .$rip. "<br />";
echo "\t ISP: " .$query->isp . "<br />";
echo "\t Organization: " .$query->org . "<br />";
echo "\t City: " .$query->city . "<br />";
echo "\t Region: " .$query->regionName . "<br />";
echo "\t Country: " .$query->country . "<br />"; 

?>

<form name="input" action="#" method="get">
IP: <input type="text" name="ip">
<input type="submit" value="Submit">
</form>

$ip 変数内で間違っていると思うので、$rip に変更しました。

于 2013-05-09T01:31:38.577 に答える