PDO::CASE_NATURAL, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::ATTR_STRINGIFY_FETCHES => false, PDO::ATTR_EMULATE_PREPARES => false, PDO::MYSQL_ATTR_INIT_COMMAND => " SET SESSION sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION', time_zone = '+00:00'; ", ]); $pdo->exec('DELETE FROM `fm_whois` WHERE `whois_timestamp` < NOW() - INTERVAL 30 MINUTE'); } catch(Exception $ex) { die($ex->getMessage()); } $domain = isset($_GET['domain']) && is_string($_GET['domain']) ? idn_to_ascii(mb_strtolower($_GET['domain']), IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46) : ''; $domainHash = hash('sha256', $domain); if(!empty($domain)) { $getDomain = $pdo->prepare('SELECT `whois_result` FROM `fm_whois` WHERE `whois_hash` = :hash'); $getDomain->bindValue('hash', $domainHash); $result = $getDomain->execute() ? json_decode($getDomain->fetchColumn()) : null; if($result === null) { $whois = new Whois\Client; try { $result = $whois->lookup($domain); $setDomain = $pdo->prepare('REPLACE INTO `fm_whois` (`whois_hash`, `whois_result`) VALUES (:hash, :result)'); $setDomain->bindValue('hash', $domainHash); $setDomain->bindValue('result', json_encode($result)); $setDomain->execute(); } catch (Whois\WhoisException $ex) { $error = $ex->getMessage(); } } } 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(!isset($result)) { $result = new stdClass; } $result->responseText = $responseText; die(json_encode($result)); } ?>