2

I'm trying to get dns records of a domain through dns_get_record() but the function doesn't seem to work when a variable is inserted..here's my code

<form action="" method="post">
     <input type="text" name="host" placeholder="Enter IP or Domain"/>
     <select name="dns">
          <option value="DNS_A" selected="selected">A</option>
               ....
          <option value="DNS_ANY">ANY</option>
     </select>
</form>
<?php
$host=$_POST['host'];
$dns=$_POST['dns'];
$type=end(explode('_',$dns));
if ($host==""){
     exit();
}
echo "Results for $host $type record<br />";
$result = dns_get_record($host, $dns);
echo "Result = ";
print_r($result);
?>

but if i put

$result = dns_get_record($host, DNS_A);

instead of

$result = dns_get_record($host, $dns);

it works..help!

3
  • 3
    Learn what a constant is: php.net/constants Commented Dec 1, 2012 at 11:55
  • @ppeterka That is a constant for once, not a string! Don't quote it. Commented Dec 1, 2012 at 11:58
  • @deceze I didn't even think of that - I blindly (and dumbly) defaulted to the usual "not escaped string" issue I saw too many times... Commented Dec 1, 2012 at 12:02

2 Answers 2

3

DNS_A is a constant of value 1, while you are passing string "DNS_A", try by passing value of constant, using $result = dns_get_record($host, constant($dns));

Sign up to request clarification or add additional context in comments.

1 Comment

it worked..but $host works even without passing a value of constant?
3

This is because your POST returns a literal string: "DNS_A", if you prefer. This is NOT the same as DNS_A, which is a constant and most likely contains an integer.

You'll need a mapping table for this one. Or just pass the integer value straight off.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.