示例包含2个文件:
1.index.php是查询选择页面,可以选择任意的域名后缀
2.get2页面是进行查询和回显的页面
注意:由于我是的页面是UTF-8编码的,而回显的是GB2312编码的汉字,所以会有乱码,相信大家可以自己调节。
1.INDEX.PHP页面代码
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<form name="domainform" method="post" action="get2.php">
<p>
<label for="textfield">www.</label>
<input type="text" name="domain" >
<input type="submit" value="查询">
</p>
<p>
<label>
<input type="checkbox" name="com" value=".com" >
.com</label><br>
<label>
<input type="checkbox" name="cn" value=".cn" >
.cn</label><br>
<label>
<input type="checkbox" name="net" value=".net">
.net</label><br>
</p>
</form>
</body>
</html>
2.GET2.PHP页面代码
<?php
/*
//域名查询结果有三个状态:
//210:可以注册
//211:已经注册
//212:参数错误
//214:未知错误
*/
/* 开始声明变量 */
$domain_last_all = array('com', 'cn', 'net');
$domain_last = array(); //获取到的域名后缀数组array();
$domain; //获取到的域名
/* 结束声明变量 */
//获取到的域名
$domain = $_POST['domain'];
/////////////////////////////////////
//调试专区
if ($domain != "" && isset($domain)) {
$domain_last = get_domain_last($domain_last_all);
query_domain($domain, $domain_last);
//print_r($domain_last);
} else {
echo '未输入域名!';
}
//////////////////////////////////////
/* 开始申明函数 */
//循环获取到的域名后缀经过判断后放入数组
function get_domain_last($domain_last_all) {
//循环预设域名后缀
$post = $_POST;
$domain_last = array();
foreach ($domain_last_all as $value) {
$domain = $post[$value];
//将非空的域名后缀放入数组$domain_lase
if ($domain != "") {
$domain_last[] = $domain;
}
}
return $domain_last;
}
//对传过来的查询条件,进行循环查询
function query_domain($domain, $domain_last) {
if ($domain != "" && isset($domain)) {
foreach ($domain_last as $value) {
//每次初始化为空值
$domain_string="";
$domain_string=$domain.$value;
echo $domain;
echo $value;
$xml_arr=query($domain_string);
show($xml_arr);
}
}
}
//查询接口
function query($domain) {
$do = "http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=" . $domain;
$xml_data = file_get_contents($do);
$xml_arr = (array) simplexml_load_string($xml_data);
return $xml_arr;
}
//显示接口
function show($result_arr){
$returncode=$result_arr['returncode'];
$key=$result_arr['key'];
$original=$result_arr['original'];
$status= substr($original,0,3);
//申明返回值
$result;
if($status=="210"){
echo "可以注册";
}else if($status=="211"){
echo "已经注册";
}else if($status=="212"){
echo "参数错误";
}
}
//打印变量的函数 后期可删除
function dump($socu) {
print_r($socu);
}
/* 结束申明函数 */
?>
3、效果图:

查询结果
4、万网域名注册查询接口(API)的说明
1、域名查询
接口采用HTTP,POST,GET协议:
调用URL:http://panda.www.net.cn/cgi-bin/check.cgi
参数名称:area_domain 值为标准域名,例:hichina.com
调用举例:http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=hichina.com
返回XML:
HTML代码
<?xml version="1.0" encoding="gb2312"?><property> <returncode>200</returncode><key>2zher3r3r.com</key> <original>210 : Domain name is available</original> </property>
返回 XML 结果说明:
returncode=200 表示接口返回成功
key=***.com表示当前check的域名
original=210 : Domain name is available 表示域名可以注册
original=211"" : Domain name is not available 表示域名已经注册
original=212 : Domain name is invalid 表示域名参数传输错误
2、域名信息whois
接口采用HTTP,POST,GET协议:
调用URL:http://whois.hichina.com/cgi-bin/whois
参数名称:domain 值为标准域名,例:hichina.com
调用举例:http://whois.hichina.com/cgi-bin/whois?domain=hichina.com
返回文本:其中在字符《pre》与字符《/pre》之间即为域名信息内容。
