[返回首页]
 ◎ 您当前的位置:首页 >> 站长学堂 >> 源码大全 >> 正文
利用 QQWry.Dat 实现 IP 地址高效检索( PHP XML-RPC 接口)
作者:未知 来源:网上收集 发布时间:2007-3-23 22:19:32

在前面利用 QQWry.Dat 实现 IP 地址高效检索(PHP) 和 利用 QQWry.Dat 实现 IP 地址高效检索(PHP 共享内存版)的基础上,我们只需再写一点儿代码,就可以实现一个 PHP XML-RPC 的查询接口了。

下面是有用共享内存版实现的程序:

<?php
include('xmlrpc.inc.php');
include('xmlrpcs.inc.php');
include('iplocation.inc.php');

function iplocation_xmlrpc($params) {
$ipval = $params->getParam(0);
$ip = $ipval->scalarval();
$iplocation = & IpLocation::getInstance();
$location = $iplocation->getlocation($ip);
if (function_exists('iconv')) {
$location['country'] = iconv("GBK", "UTF-8", $location['country']);
$location['area'] = iconv("GBK", "UTF-8", $location['area']);
}
else if (function_exists('mb_convert_encoding')) {
$location['country'] = mb_convert_encoding($location['country'], "UTF-8", "GBK");
$location['area'] = mb_convert_encoding($location['area'], "UTF-8", "GBK");
}
else {
return new xmlrpcresp(0, $xmlrpcerruser, "Can't convert the result to the correct encode.");
}
return new xmlrpcresp(new xmlrpcval(array(
"ip" => new xmlrpcval($location['ip'], "string"),
"beginip" => new xmlrpcval($location['beginip'], "string"),
"endip" => new xmlrpcval($location['endip'], "string"),
"country" => new xmlrpcval($location['country'], "string"),
"area" => new xmlrpcval($location['area'], 'string')), "strUCt"));
}

new xmlrpc_server(array('iplocation' =>
array('function' => 'iplocation_xmlrpc',
'signature' => array(array('struct', 'string')),
'docstring' => 'Return the location of the ip or domain name.'))
);

?>


有了这个 XML-RPC 服务器,我们就可以在任何程序中去调用它了

[返回上一页] [打 印]
热点文章 推荐文章
·使用301重定向
·时间、空间性能极优的asp无组件上传类
·whois信息查询大全
·鼠标经过就跳出的代码
·四大机器人的代码
·实现百度站内搜索的代码
·让广告代码不再影响你的网页加载速度
·打开网页自动设为首页代码
·适合本blog的一个精美javascript日历
·挂QQ的上下线和隐身
·让网页跳转的几种方法
·滚动条特效代码收集