<?php
error_reporting(E_ALL);
if( isset($_POST['submit2']) && $_POST['submit2'])
{
    require  "IpLocation.class.php";
    $ipLocation = new IpLocation("./qqwry.dat");
	$input=$_POST['input']?$_POST['input']:getIP();
	$ips = $ipLocation->getlocation($input) ;
	$ipStr=$ips['country'];
	//$ipStr = iconv('gbk','utf-8',isset($ips['country'])?$ips['country']:"");
	
	echo $ipStr;
}
/* 获取用户真实 IP
 *
 * @Author: 
 * @Return: string
 */
function getIP()
{
    static $realip;
    if (isset($_SERVER)){
        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
            $realip = $_SERVER["HTTP_X_FORWARDED_FOR"];
        } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {
            $realip = $_SERVER["HTTP_CLIENT_IP"];
        } else {
            $realip = $_SERVER["REMOTE_ADDR"];
        }
    } else {
        if (getenv("HTTP_X_FORWARDED_FOR")){
            $realip = getenv("HTTP_X_FORWARDED_FOR");
        } else if (getenv("HTTP_CLIENT_IP")) {
            $realip = getenv("HTTP_CLIENT_IP");
        } else {
            $realip = getenv("REMOTE_ADDR");
        }
    }

    return $realip;
}
?>   <a href="">刷新</a>
<form method="post" action="">
 <input type="text" name="input"/>
 <input type="submit" name="submit2" value="查询" />
 </form>