note 119579 added to function.dns-get-record
| From: | pizzafried at gmail dot com | Date: | Mon, 11 Jul 2016 11:39:27 +0000 |
| Subject: | note 119579 added to function.dns-get-record | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205962@lists.php.net to get a copy of this message | ||
I found that this code does not get the correct records all the time (at least not our PHP version).
It has something to do with CNAMES therefore, you should do something like this:
<?php
function dns_get_valid_record($domain, $type=DNS_MX, $root = 0){
$result = dns_get_record("".$domain."", $type); //first try to find it
this way.
if(!$result){
//check for cname;
$result = dns_get_record("".$domain."", DNS_CNAME); //check if it is
a cname, and if so, try that domain.
if($result && $result[0]["target"]){
return dns_get_valid_record($result[0]["target"],$type);
}else{
//if not, translate www.example.com to example.com, and try again.
$domain = explode(".", $domain);
if(count($domain)>2 && $root==0) {
$domain = $domain[count($domain) - 2] . "." . $domain[count($domain) -
1];
return dns_get_valid_record($domain, $type,1);
}
}
}else {
foreach($result as $key=>$record){
if(isset($record["target"]) &&
!filter_var($record["target"], FILTER_VALIDATE_IP)){ //no ip?
if(!dns_get_valid_record($record["target"], DNS_A)){ //we validated
one: check if we get anywhere (A or CNAME=>A)
unset($result[$key]);
}
}
}
}
return $result;
}
?>
you can look up anything else, but this is primarily designed for getting MX records and test if
they could exist. the IP address could still not be in the air or not the correct one, but DNS will
be properly setup when returned results.
----
Server IP: 72.52.91.14
Probable Submitter: 83.86.92.251
----
Manual Page -- http://php.net/manual/en/function.dns-get-record.php
Edit -- https://master.php.net/note/edit/119579
Del: integrated -- https://master.php.net/note/delete/119579/integrated
Del: useless -- https://master.php.net/note/delete/119579/useless
Del: bad code -- https://master.php.net/note/delete/119579/bad+code
Del: spam -- https://master.php.net/note/delete/119579/spam
Del: non-english -- https://master.php.net/note/delete/119579/non-english
Del: in docs -- https://master.php.net/note/delete/119579/in+docs
Del: other reasons-- https://master.php.net/note/delete/119579
Reject -- https://master.php.net/note/reject/119579
Search -- https://master.php.net/manage/user-notes.php