下面是完整的用于查询域名信息和回应 Ajax 请求 PHP 源代码:
<?php $domain = htmlspecialchars(trim($_GET['domain'])); if( !$domain ){ echo '请输入要查询的域名,如:520mg.com'; exit; } // 调用万网域名查询API $area_domain = iconv("utf-8", "gb2312",$domain); $domain_api = 'http://panda.www.net.cn/cgi-bin/check.cgi?area_domain='.$area_domain; $contents = file_get_contents($domain_api); $xml = simplexml_load_string($contents); if (!empty($xml)) { switch($xml->original) { case '210 : Domain name is available':$result = '该域名可以注册';break; case '211 : Domain name is not available':$result = '该域名已经被注册';break; case '212 : Domain name is invalid':$result = '域名参数错误,请输入的域名格式';break; case '214 : Unknown error':$result='查询异常,请稍后再试';break; } } else { // 备用,只能查询国际域名 $url = 'http://www.checkdomain.com/cgi-bin/checkdomain.pl?domain='.$_GET; $fp = file_get_contents($url); if( strpos($fp, ', has already been registered') ){ $result = '该域名已经被注册'; } else { $result = '该域名可以注册'; } } echo '<b>'.$domain.'</b>:'.$result; ?>