The first loop gets the 2 values for hostkarma just fine. The 2nd loop fails for accredit.habeas and I get “Invalid argument supplied for foreach() on line 11″. Where am I going wroge with the “foreach($value as $val)” loop?
$hosts = array(’209.49.180.233′,’209.49.180.234′);
foreach ($hosts as $host) // Loop for IP addresses
{
$rbls = array(‘hostkarma.junkemailfilter.com’,'accredit.habeas.com’);
foreach ($rbls as $rbl) // Loop for domains
{
$hostname = gethostbyaddr( $host );
$lookup = $hostname . ‘.’ . $rbl;
$value = gethostbynamel($lookup);
foreach($value as $val) // loop for multiple record/code values
{
echo $host, $rbl, $val . “”;
}
}
}
………………………………………
You must add:
if (is_array($value))just before foreach($value as $val) line.
For the cases when gethostbynamel is failing its return value $value is not an array hence causing Invalid argument supplied for foreach() error.
………………………………………
The documentation says that gethostbynamel returns FALSE if cannot resolve the hostname and that gethostbyaddr returns the unmodified ip address on failure.
So check the results that are being returned by these functions and do something sensible if one of them fails.