<?php
$code = $_GET['code'];
if(preg_match('/^[0-9a-zA-Z]{3,8}$/', $code, $match))
{
	$dir = str_replace( '\\', '/', dirname( __FILE__ ).'/');
	$cofig = include($dir.'../mvc/dwz.config.php');
	include($dir.'../mvc/lib/LibDb.php');
	$MainDb = new LibDb ($cofig['DB']['MAIN']);
	$sql = sprintf("select url from dwz where code='%s'", $code);
	$realurl = $MainDb->One($sql);
	if(!empty($realurl) && stripos($realurl, 'http') == 0)
	{
		$set = sprintf("update dwz set click=click+1, etime=%d where code='%s'", time(), $code);
		$MainDb->Query($set);
		header('Location: '.$realurl, true, 302);
		exit;
	}
}
header('HTTP/1.1 404 Not Found');