Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8021653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:03:02+00:00 2026-06-04T22:03:02+00:00

The following form is returning true all the time, even if the domain is

  • 0

The following form is returning true all the time, even if the domain is available. Can anyone let me know what I’m doing wrong? Thanks.

<?php
function domainAvailable($domain){
$results = @dns_get_record($domain, DNS_ANY);
return empty($results);
}
if (isset($_REQUEST['domain']))  // check to see if form has been submitted
{
$domain = htmlspecialchars($_REQUEST['domain'], ENT_QUOTES, 'UTF-8');

$httpdomain = 'http://' . $domain;

    if (domainAvailable($httpdomain) == true){
        echo "$domain is not available.";
        if (domainAvailable($httpdomain) == false){
            echo "$domain is available!";   
        }
    }
}
?>
<form method="post" action="">
<div>
<label for="domain name">Suggest a Domain:</label> <input type="text" name="domain" /><br />
<input type="submit" />
</div>
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:03:03+00:00Added an answer on June 4, 2026 at 10:03 pm

    Start by untangling your ifs:

    if (domainAvailable($httpdomain)){
       echo "$domain is not available.";
    } else {
       echo "$domain is available!"; 
    }
    

    Also, you probably have your strings backwards

    if (domainAvailable($httpdomain)){
       echo "$domain is available.";
    } else {
       echo "$domain is not available!"; 
    }
    

    Then, get rid of this line:

    $httpdomain = 'http://' . $domain;
    

    Your domainAvailable function is probably going to always return true because http:// is not part of a valid domain name

    The call to htmlspecialchars is probably going to cause false negatives as well.

    Put it all together:

    <?php
    #CLI debugging:
    if(empty($_REQUEST['domain']) && !empty($argv[1]))
        $_REQUEST['domain'] = $argv[1];
    
    function domainAvailable($domain) {
        $results = @dns_get_record($domain, DNS_ANY);
        return empty($results);
    }
    
    if (isset($_REQUEST['domain']))  // check to see if form has been submitted
    {
        $domain = htmlspecialchars($_REQUEST['domain'], ENT_QUOTES, 'UTF-8');
    
        if (domainAvailable($_REQUEST['domain'])) {
            echo "$domain is available.";
        } else {
            echo "$domain is not available!";
        }
    }
    

    Sample output:

    $ php scratch.php google.com | more
    google.com is not available!
    $ php scratch.php googleasdfasdf.com. | more
    googleasdfasdf.com. is available.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi can anyone please tell me why the following code is only returning the
I have the following form, which I have reduced as much as I can,
I know this is a simple question, but can you all help me with
I have the following form: = form_for([current_user,@company], :remote => true) do |f| -if @company.errors.any?
I have the following form in a Struts2 JSP that contains some radio buttons.
I have the following form: @model Teesa.Models.SearchModel @using (Html.BeginForm(Index, Search, FormMethod.Get, new { id
I have the following form and controller. <%= form_tag do %> <div> <%= label_tag
I have the following form: echo $this->Form->input('Person.name'); echo $this->Form->input('Person.phone'); echo $this->Form->input('Person.email'); echo $this->Form->input('Message.0.plainmsg'); echo
I have the following form for photo_album which uses the nested forms feature of
I have the following form <form name=myForm id=myForm method=post enctype=multipart/form-data action=script.php> and this jQuery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.