Check multiple whois requests in a textarea
I would开发者_JAVA技巧 like to create a whois function that can check availability for multiple domains (many different words at the same time).
I have this script which works for one single word. How can I get it to check multiple words (one word on each row in the textarea)?
For example if I type in to following in the textarea:
goodword
averygoodword
thisisagreatword
Here is the code:
<?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>
You should be able to split the lines in the textarea into an array using explode with a newline delimiter, then do your WHOIS lookups in a foreach loop.
$manydomains = explode("\n", $domainbase);
foreach ($manydomains as $domain){
<your code here>
}
精彩评论