<?php

include_once "../common.inc.php";
AccessCheck();

if(empty($_GET["q"]) || empty($_GET["vid"]) || !isset($profile)) {
	exit();
}

@set_time_limit(6);
$q = $_GET["q"];
$vid = $_GET["vid"];


$query = $db->Execute("SELECT customlabel FROM {$profile->tablename_visitorids} WHERE visitorid = ". $db->Quote($vid) );
$r = $query->fetchRow();

if(!empty($r['customlabel'])){
	echo $r['customlabel'];

} else {
	$response = @gethostbyaddr($q);
	if($response === false){
		$response = "-";
	}
	$db->Execute("UPDATE {$profile->tablename_visitorids} SET customlabel=". $db->Quote($response) ." WHERE visitorid=". $db->Quote($vid) );

	echo $response;
}
?>
