如何使用dns_get_record仅显示带有复选框的选定域扩展名

时间:2014-08-07 11:04:04

标签: php checkbox dns get record

我尝试使用复选框仅检查选定的域扩展名,但会检查阵列中存在的所有域扩展名。

这是我正在尝试的。

    $name_domain = trim($_POST['domain_name']).$_POST['suffix'];
    $domains = array(
    ($name_domain) ? trim($_POST['domain_name']).$_POST['suffix'] : '',
    (isset($_POST['_org'])) ? trim($_POST['domain_name']).'.org' : trim($_POST['domain_name']).$_POST['_org'],
    (isset($_POST['_net'])) ? trim($_POST['domain_name']).'.net' : trim($_POST['domain_name']).$_POST['_net'], 
    (isset($_POST['_biz'])) ? trim($_POST['domain_name']).'.biz' : trim($_POST['domain_name']).$_POST['_biz'],
    (isset($_POST['_ws'])) ? trim($_POST['domain_name']).'.ws' : trim($_POST['domain_name']).$_POST['_ws'],
    (isset($_POST['_mobi'])) ? trim($_POST['domain_name']).'.mobi' : trim($_POST['domain_name']).$_POST['_mobi'],
    (isset($_POST['_info'])) ? trim($_POST['domain_name']).'.info' : trim($_POST['domain_name']).$_POST['_info'],
    );
    $msg='';
    foreach($domains as $d){
        $response = @dns_get_record($d, DNS_ALL);
        if(empty($response)){
                    $msg .= "<h2 style='color:green;' >Domain $d is available.</h2>";
        }else if(!empty($response)){
                    $msg .= "<h2 style='color:red;'>Domain $d has taken.</h2>";
        }

HTML

<td colspan="2"><input type="checkbox" name="_org" value=".org"> <label for="_org">.org</label></td>
<td colspan="2"><input type="checkbox" name="_net" value=".net"> <label for="_net">.net</label></td>
<td colspan="2"><input type="checkbox" name="_biz" value=".biz"> <label for="_biz">.biz</label></td>
<td colspan="2"><input type="checkbox" name="_ws" value=".ws"> <label for="_ws">.ws</label></td>
<td colspan="2"><input type="checkbox" name="_mobi" value=".mobi"> <label for="_mobi">.mobi</label></td>
<td colspan="2"><input type="checkbox" name="_info" value=".info"> <label for="_info">.info</label></td>

任何想法如何只显示和检查选中的扩展程序检查复选框?

1 个答案:

答案 0 :(得分:0)

试试这个

<input type="checkbox" id="_org" name="tld[]" value=".org">
<label for="_org">.org</label>

这是完整的例子,

<form method="post" action="">
<input type="text" name="domain_name" />
<table>
    <tr>
        <td colspan="2">
            <input type="checkbox" id="_org" name="tld[]" value=".org">
            <label for="_org">.org</label>
        </td>
        <td colspan="2">
            <input type="checkbox" id="_net" name="tld[]" value=".net">
            <label for="_net">.net</label>
        </td>
        <td colspan="2">
            <input type="checkbox" id="_biz" name="tld[]" value=".biz">
            <label for="_biz">.biz</label>
        </td>
        <td colspan="2">
            <input type="checkbox" id="_ws" name="tld[]" value=".ws">
            <label for="_ws">.ws</label>
        </td>
        <td colspan="2">
            <input type="checkbox" id="_mobi" name="tld[]" value=".mobi">
            <label for="_mobi">.mobi</label>
        </td>
        <td colspan="2">
            <input type="checkbox" id="_info" name="tld[]" value=".info">
            <label for="_info">.info</label>
        </td>
    </tr>
</table>
<input type="submit" name="submit" value="submit" />
</form>

$domain_name = trim($_POST['domain_name']);
$responses = array();
$msg = '';

foreach($_POST['tld'] as $tld) {
switch($tld)
{
    # white list
    case '.org':
    case '.net':
    case '.biz':
    case '.ws':
    case '.mobi':
    case '.info':

        $domain = $domain_name . $tld;
        $dns = dns_get_record($domain, DNS_ALL);

        # available
        if(count($dns) == 0) $msg .= "<h2 style='color:green;' >Domain $domain is available.</h2>";

        # error
        elseif($dns === false) $msg .= "<h2 style='color:green;' >Error on domain $domain.</h2>";

        # not available
        else
        {
            $msg .= "<h2 style='color:red;'>Domain $domain has taken.</h2>";
            $responses[$domain] = $dns;
        }

        break;
}
}

echo $msg;