Jump to content

Recommended Posts

Hi guys, I am trying to figure out how to do something here in PHP... I have a form, with a box at the top where user can enter a domain name, under this box there is a submit button and then a bunch of boxes below the submit button for all the records related to that domain.

 

I want a user to enter a domain, hit submit, PHP script looks up all records related to the domain, and then returns them back to main index.php and populates all the record fields below the submit button. Any guidance on how to do this would be appreciated.

 

I can clarify further if needed, just let me know!

In index.php I have this:

 

<form action="lookup.php" method="POST" class="form">
<label for="domain">Domain Name</label>
<div class="domain_div">
<input name="domain" type="text" class="domain_tb" id="domain" value="domain" />
</div>
<div class="button_div">
<input name="Submit" type="button" value="Look Up" class="buttons" />
</div>
</form>

 

Now, in my lookup.php file I have this:

 

<?php

ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

$domain = $_POST['domain'];

// First let's check if domain is valid (exists)
$ip = gethostbyname($domain);
if($ip === $domain)
{
    return ???;
}

// First get all records related to root domain

// Get A Records First
$dnsr = dns_get_record($domain, DNS_A );
for($i = 0; $i < count($dnsr); $i++){
    echo $dnsr[$i]["host"].'<br>';
    echo $dnsr[$i]["ip"].'<br>';
    echo '<br>';
}
?>

 

 

Now, how do I get everything from lookup.php back into index.php forms? Do I return it back in and handle it there? How to do that? Is there a better way to do this?

If I understand you correctly, this is what you need to combine the two files into one.

 

index.php(new)

if ($_SERVER['REQUEST_METHOD'] == "GET") {
     code from index.php(old)
} else {
     code from lookup.php
}

 

 

You could also do it with includes like this:

 

if ($_SERVER['REQUEST_METHOD'] == "GET") {
     include_once("form.html"); // If form.html is a new file containing just your form
} else {
     include_once("lookup.php");
}

 

Hope that helps

In the index.php page do something like this

<?php
if ($_SERVER['REQUEST_METHOD'] == "POST") {
     include('lookup.php');
} else {
?>
    <form action="lookup.php" method="POST" class="form">
    <label for="domain">Domain Name</label>
    <div class="domain_div">
    <input name="domain" type="text" class="domain_tb" id="domain" value="domain" />
    </div>
    <div class="button_div">
    <input name="Submit" type="button" value="Look Up" class="buttons" />
    </div>
    </form>
<?php
}
?>

Ahhh, alright, I get that part now, but the part I am still lost on is how, after including lookup.php, do I use the values from lookup.php to populate my text fields?

 

I am used to Perl, where I return a value (array, hash, scalar), and then use that value to populate the form...

 

If it can validate the domain it returns TRUE + All records found. If not, it returns FALSE.

 

Then, in index.php, If it returns TRUE it populates all text fields with the records, and if it returns FALSE it should have a box below that says something like "Sorry, unable to find domain."

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.