<?
header("Content-type: application/json");



$q=parse_url($_SERVER['REQUEST_URI'])["query"];
parse_str($q,$_GET);
$ip=ip2long($_GET['ip']);

if(!$ip)
  die;
require_once("inc/func.php");
require_once("inc/goods.php");

$res=array();
foreach ($goods as $ads) {
	$ad=$ads[mt_rand(1,10000)%sizeof($ads)];
	$ad=repare_ad($ad, $ip);
  $ad['cpc']=0.02;
  
  if(iconv_strlen($ad['title'])<=50 && iconv_strlen($ad['description'])<=50)
	$res[]=$ad;
}

$out=array('nurl'=>"//".$_SERVER['HTTP_HOST'].'/tnurl?ids=${AD_IDS}','data'=>$res);

echo json_encode($out,  JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
