<?php

include $_SERVER['DOCUMENT_ROOT'].'/../init.php';

$id = intval($_GET['id']);
if (!$id){
	header('Location: /');
	exit;
}

$ad_query = $db->query("SELECT link FROM ads WHERE ad_id='$id' LIMIT 1");
$ad = $db->fetch_assoc($ad_query);;

if (!$ad['link']){
	header('Location: /');
	exit;
}

$db->query("UPDATE ads SET clicks=clicks+1 WHERE ad_id='$id' LIMIT 1");
header('Location: '.$ad['link']);
exit;
