<?php
require 'common.php';
if($target=$_GET['url'])
{
	$data = get_curl($target,0,0,0,1);
	preg_match("/Location: (.*?)\r\n/iU", $data, $urls);
	if(!$urls[1]) $long_url=$target;
	else $long_url=$urls[1];
	if(strpos($long_url,'www.battleofballs.com')===false)
	{
		exit('{"code":-2}');
	}
	else
	{
		$refer = str_replace("?","/index_mobile_share.html?",$long_url);
		$account = explode('Account=',$refer);
		$account = urldecode($account[1]);
		$id = trim(getSubstr($refer,"id=","&A"));
		$sid = md5($id.date("Ymd"));
		if($row=$DB->get_row("SELECT * FROM qiu_log WHERE id='$sid' limit 1"))
		{
			exit('{"id":"'.$id.'","account":"'.$account.'","code":"1"}');
		}
		else
		{
			get_curl("http://www.dqiuqiu.com/php/do.php?url=".$target);
			$DB->query("insert into `qiu_log` (`id`,`code`,`time`) values ('".$sid."','1','".time()."')");
			exit('{"id":"'.$id.'","account":"'.$account.'","code":"0"}');
		}
	}
}
else
{
	exit('{"code":-2}');
}
?>