域名查询是否被注册的类PHP封装

widuu 2012-10-18 PHP技术 4,292 0 喜欢 (0)

前两天客户需要域名查询是否被注册的方法,我就封装了一个简单的类 因为时间匆忙,没有改善,希望朋友们看到了一块帮忙完善一下
谢谢大家现在放出源码;
[php]
//这是类方法
<?php
/**
* 域名查询类
*
* @copyright Copyright (c) 2012, Widuu, Inc.
* @author Porwered BY 肖伟
* @link http://www.widuu.com
*/
class Domain{

private $domain_last_all=array('com', 'cn', 'net'); //包含的后缀名
private $domain_last; //封装的后缀名
private $name;

function __construct($name=""){
$this->domain_last=$this->get_domain_last($this->domain_last_all);
$this->name=$name;
}
//对传过来的查询条件,进行循环查询
private 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=$this->query($domain_string);
$this->show($xml_arr);
}
}
}
//查询接口
private 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;
}
//显示接口
private 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 "参数错误";
}
}
//循环获取到的域名后缀经过判断后放入数组
private function get_domain_last($domain_last_all){
$post = $_POST;
//循环预设域名后缀
$domain_last = array();
foreach ((array)$domain_last_all as $value) {
//将非空的域名后缀放入数组$domain_last
$domain = $post[$value];
if ($domain != "") {
$domain_last[] = $domain;
}
}
return $domain_last;
}

function domain(){
$name=$this->name;
$domain=$_POST["{$this->name}"];
if ($domain != "" && isset($domain)) {
$domain_last = $this->get_domain_last($this->domain_last_all);
$this->query_domain($domain,$domain_last);
} else {
echo '未输入域名!';
}
}
}
//实例化类调用类
<?php
header('content-type:text/html;charset=utf-8');
include ("Domian.class.php");
$domian=new Domain('domain');
$domian->domain();
?>
//前台界面
<form method="post" action="4.php">
<input type="text" name="domain">
<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>
<input type="submit" value="提交">
</form>
[/php]
欢迎转载,转载请注明来自微度网络http://www.widuu.com

转载请注明来自微度网络,本文标题:《域名查询是否被注册的类PHP封装》

喜欢 0 发布评论
Top