connect('/var/run/redis/redis-server.sock'); $result = $redis->get(FMWHOIS_PREFIX . $domainHash); if(empty($result)) { $whois = new Whois\Client; try { $result = $whois->lookup($domain); $redis->setEx(FMWHOIS_PREFIX . $domainHash, 1800, json_encode($result)); } catch (Whois\WhoisException $ex) { $error = $ex->getMessage(); } } else { $result = json_decode($result); } } if(!empty($error)) { $responseText = $error; } elseif(!empty($result)) { $responseText = ''; switch($result->type) { case 'domain': foreach($result->responses as $server => $response) { $responseText .= "{$result->target} domain lookup results from {$server}\r\n\r\n"; $responseText .= trim($response) . "\r\n"; } break; case 'ip': $responseText .= "RESULTS FOUND: " . count($result->responses); foreach($result->responses as $server => $response) { $responseText .= "-------------\r\n"; $responseText .= "Lookup results for {$result->target} from {$server}:\r\n\r\n"; $responseText .= trim($response) . "\r\n"; } break; default: $responseText .= 'Something happened.'; break; } } else { $responseText = 'Enter a domain or IP address!'; } if(isset($_GET['ajax'])) { header('Content-Type: application/json; charset=utf-8'); if(!is_object($result)) $result = new stdClass; $result->responseText = $responseText; die(json_encode($result)); } ?>