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!
-
3Learn what a constant is: php.net/constantsdeceze– deceze ♦2012年12月01日 11:55:30 +00:00Commented Dec 1, 2012 at 11:55
-
@ppeterka That is a constant for once, not a string! Don't quote it.deceze– deceze ♦2012年12月01日 11:58:11 +00:00Commented 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...ppeterka– ppeterka2012年12月01日 12:02:25 +00:00Commented Dec 1, 2012 at 12:02
2 Answers 2
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));
-
it worked..but
$host
works even without passing a value of constant?nitish– nitish2012年12月01日 12:10:50 +00:00Commented Dec 1, 2012 at 12:10
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.