我需要添加两个要求。
此转移到下面提到的错误消息(错误:域名不能留空。)
<form action="" method=post>
<table>
<tr>
<td><input type="text" name="domain_name" style="width:170px;"></td>
<td>
<select name="suffix" style="width:75px;">
<option value=".sk" align="left">.sk</option>
</select>
</td>
</tr>
<tr>
<td><input type="submit" id="popUpYes" name="check" value="Check"></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['check'])) {
if (!empty($_POST['domain_name'])){
$name_domain = trim($_POST['domain_name']).$_POST['suffix'];
$response = @dns_get_record($name_domain, DNS_ALL);
if(empty($response)){
echo "<span style='color:red;'>Domain is free.</span>";
}else{
echo "<span style='color:red;'>Domain is registered.</span>";
}
}
else {
echo "<span style='color:red;'>Error: Domain name can not be left empty.</span>";
}
}
?>
答案 0 :(得分:0)
<?php
if(isset($_POST['check'])) {
if (!empty($_POST['domain_name'])){
if (strlen ($_POST['domain_name']) > 3){
if (preg_match ("/^\w+$/", $_POST['domain_name'] )){
$name_domain = trim($_POST['domain_name']).$_POST['suffix'];
$response = @dns_get_record($name_domain, DNS_ALL);
if(empty($response)){
echo "<span style='color:red;'>Domain is free.</span>";
}else{
echo "<span style='color:red;'>Domain is registered.</span>";
}
}
else {
echo "<span style='color:red;'>Error: Domain name characters must to be alphanumeric.</span>";
}
}
else {
echo "<span style='color:red;'>Error: Domain name must contain at least 3 characters.</span>";
}
}
else {
echo "<span style='color:red;'>Error: Domain name can not be left empty.</span>";
}
}
?>
答案 1 :(得分:0)
if(empty($response)){
if(preg_match('/[^-_a-z0-9.]/iu', $_POST['domain_name'])){
if(strlen(strpbrk($_POST['domain_name'], '.')) > 3) {
echo "<span style='color:red;'>Domain is free.</span>";
}
}
}