我想创建一个 whois 函数,可以检查多个域的可用性(同时有许多不同的词)。
我有一个适用于一个单词的脚本。如何让它检查多个单词(文本区域中每一行一个单词)?
例如,如果我在 textarea 中输入以下内容:
好词
非常好词
这个好词
这是代码:
<?php function checkDomain($domain,$server,$findText){
// Open a socket connection to the whois server
$con = fsockopen($server, 43);
if (!$con) return false;
// Send the requested doman name
fputs($con, $domain."\r\n");
// Read and store the server response
$response = ' :';
while(!feof($con)) {
$response .= fgets($con,128);
}
// Close the connection
fclose($con);
// Check the response stream whether the domain is available
if (strpos($response, $findText)){
return true;
}
else {
return false;
}
}
function showDomainResult($domain,$server,$findText){
if (checkDomain($domain,$server,$findText)){
echo "<div id='left'>$domain</div><div id='next'>AVAILEBLE</div><div id='nycontainer'></div>";
}
else echo "<div id='left'>$domain</div><div id='next'>TAKEN</div><div id='nycontainer'></div>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><?php $sidtitel ?></title>
<link href="exempel1.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="titel"> <h1>Search domain</h1></div>
<div id="main">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="domain" id="domain">
<textarea name="domainname"></textarea>
<input type="checkbox" name="all" checked />All
<input type="checkbox" name="se"/>.se
<input type="checkbox" name="nu"/>.nu
<input type="checkbox" name="eu"/>.eu
<input type="checkbox" name="biz"/>.biz
<input type="checkbox" name="com"/>.com
<input type="checkbox" name="net"/>.net
<input type="checkbox" name="org"/>.org
<input type="checkbox" name="info"/>.info
<input class="text" type="submit" name="submitBtn" value="Sök domännamn"/>
</form>
<?php
if (isset($_POST['submitBtn'])){
$domainbase = (isset($_POST['domainname'])) ? $_POST['domainname'] : '';
$d_all = (isset($_POST['all'])) ? 'all' : '';
$d_se = (isset($_POST['se'])) ? 'se' : '';
$d_nu = (isset($_POST['nu'])) ? 'nu' : '';
$d_eu = (isset($_POST['eu'])) ? 'eu' : '';
$d_biz = (isset($_POST['biz'])) ? 'biz' : '';
$d_com = (isset($_POST['com'])) ? 'com' : '';
$d_net = (isset($_POST['net'])) ? 'net' : '';
$d_org = (isset($_POST['org'])) ? 'org' : '';
$d_info = (isset($_POST['info'])) ? 'info' : '';
// Check domains only if the base name is big enough
if (strlen($domainbase)>2){
?>
<h1>Results</h1>
<div id="result">
<?php
if (($d_se != '') || ($d_all != '') ) showDomainResult($domainbase.".se",'whois.iis.se','not found');
if (($d_nu != '') || ($d_all != '') ) showDomainResult($domainbase.".nu",'whois.nic.nu', 'NO MATCH for');
if (($d_eu != '') || ($d_all != '') ) showDomainResult($domainbase.".eu",'whois.eu','AVAILABLE');
if (($d_biz != '') || ($d_all != '') ) showDomainResult($domainbase.".biz",'whois.nic.biz','Not found');
if (($d_com != '') || ($d_all != '') ) showDomainResult($domainbase.".com",'whois.crsnic.net','No match for');
if (($d_net != '') || ($d_all != '') ) showDomainResult($domainbase.".net",'whois.crsnic.net','No match for');
if (($d_org != '') || ($d_all != '') ) showDomainResult($domainbase.".org",'whois.publicinterestregistry.net','NOT FOUND');
if (($d_info != '') || ($d_all != '') ) showDomainResult($domainbase.".info",'whois.afilias.net','NOT FOUND');
?>
</div></div>
<?php
}
}
?>
</body>