赞
踩
一、利用php的soap扩展
( extension=php_openssl.dll extension=php_soap.dll php.ini 这2项要开通 )
利用http://webservice.webxml.com.cn/提供的获取ip地址的webservices
$client = new SoapClient("http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl");
echo '
';
print_r($client->__getFunctions ()) ;// 获取webservice提供的函数
echo '
';$myip = $out->getGeoIPContextResult->string;
echo '
';
print_r($myip);
echo '
';$param = array('theIpAddress'=>'192.168.1.1');//注意参数
$out = $client->getCountryCityByIp($param);
$arr = $out->getCountryCityByIpResult->string;
echo '
';
print_r($arr);
echo '
';?>
输出的结果:
Array
(
[0] => getCountryCityByIpResponse getCountryCityByIp(getCountryCityByIp $parameters)
[1] => getGeoIPContextResponse getGeoIPContext(getGeoIPContext $parameters)
[2] => getVersionTimeResponse getVersionTime(getVersionTime $parameters)
[3] => getCountryCityByIpResponse getCountryCityByIp(getCountryCityByIp $parameters)
[4] => getGeoIPContextResponse getGeoIPContext(getGeoIPContext $parameters)
[5] => getVersionTimeResponse getVersionTime(getVersionTime $parameters)
[6] => ArrayOfString getCountryCityByIp(string $theIpAddress)
[7] => ArrayOfString getGeoIPContext()
[8] => string getVersionTime()
[9] => ArrayOfString getCountryCityByIp(string $theIpAddress)
[10] => ArrayOfString getGeoIPContext()
[11] => string getVersionTime()
)
Array
(
[0] => 211.103.248.103
[1] => 北京市昌平区 电信通
)
Array
(
[0] => 192.168.1.1
[1] => 局域网 对方和您在同一内部网
)
二、服务器不支持soap扩展的情况下,可引入网上开源的类库:
include("lib/nusoap.php");
$client = new SoapClient("http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl","wsdl");
$client->soap_defencoding = 'utf-8';
$client->decode_utf8 = false;
$client->xml_encoding = 'utf-8';
$out = $client->call('getGeoIPContext');
echo '
';
print_r($out) ;
echo '
';$param = array('theIpAddress'=>'202.173.45.28');//注意参数
$out = $client->call('getCountryCityByIp',$param);
echo '
';
print_r($out) ;
echo '
';?>
输出的结果:
Array
(
[getGeoIPContextResult] => Array
(
[string] => Array
(
[0] => 211.103.248.103
[1] => 北京市昌平区 电信通
)
)
)
Array
(
[getCountryCityByIpResult] => Array
(
[string] => Array
(
[0] => 95.173.45.28
[1] => 美国
)
)
)
{jcomments on}{jcomments off}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。