【问题标题】:Lookup a specific IP address entered by form查找通过表单输入的特定 IP 地址
【发布时间】:2013-05-03 09:15:56
【问题描述】:

我有一个脚本,它使用 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 />"; 

?>

【问题讨论】:

  • 抱歉我没听懂!!?
  • 远程地址是$ip,但是你查询$rip,它也不应该用引号引起来,所以我假设它默认为本地
  • 是的,你说得对,但它工作得很好,我只需要表格,这样访客就可以录制他想要的 ip 并获取信息,对不起,我的英语很差:P,我希望你知道我是什么想说:)

标签: php forms api ip lookup


【解决方案1】:

你应该有一个 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。

【讨论】:

  • 非常感谢 nirock,你是天才 hihi :P 效果很好,
  • 然后,您可以勾选我的答案作为正确答案。这样其他人也将能够知道正确的答案...
  • 完成 :) !!如果我把这个表格放在我的主页上,当你点击提交时,结果会出现在其他页面名称中,它是lookup.php?我该怎么办?
  • 只需将
    更改为
  • 非常感谢您对我的帮助,我真的很感激,我只是想学习 php,首先当我将其更改为
    直到我也改变它才起作用
猜你喜欢
  • 2012-11-29
  • 1970-01-01
  • 2020-11-01
  • 2012-08-16
  • 2021-12-01
  • 2015-10-18
  • 2012-07-08
  • 2013-02-27
  • 1970-01-01
相关资源
最近更新 更多