<style type="text/css">
.center {
  margin: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -ms-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
</style>


  <div class="center">
   <img src="assets/img/loading.gif" style="max-width: 100%;">
   <img src="https://a.piclect.com/m161026_6c217.gif" style="max-width: 100%;">
  </div>


<!-- 
  <div class="vertical-center">
	<center><img src="https://themes.potenzaglobalsolutions.com/cupidlovedesign/intro/ios/customizing-app/assets/images/loading.gif"></center>
  </div>
 -->

<?php
include 'config.php';

$player_id = $_GET['userId'];
$user_token = $_COOKIE['user_token'];
$user_onesignal = $_COOKIE['user_onesignal'];
$ip = $_SERVER['REMOTE_ADDR'];
$useragent = $_SERVER['HTTP_USER_AGENT'];
$suan = time();

echo $player_id;



if(!empty($player_id)){
setcookie("user_onesignal", $player_id, time() + (365*60*60*24));
}else{
	echo "ONLY USE MOBILE APP!";
}


if(!empty($user_token)){


$userCheck = $db->query("SELECT COUNT(*) FROM kullanicilar where user_token = '{$user_token}'")->fetchColumn();

if($userCheck != 0){

$query = $db->prepare("UPDATE kullanicilar SET
user_songiris = :bir,
user_agent = :dort,
user_ip = :uc,
user_onesignal = :bes
WHERE user_token = :iki");
$update = $query->execute(array(
     "bir" => $suan,
     "dort" => $useragent,
     "uc" => $ip,
     "bes" => $player_id,
     "iki" => $user_token
));

if($update){
	echo '{"result":"1x"}';
	header("Location: index.php");
}else{
	echo '{"result":"0x"}';
	header("Location: index.php");
}

}else{
	echo '{"result":"0x"}';
	header("Location: index.php");
}

}else{

$coPlayer2 = $db->query("SELECT * FROM not_registered WHERE player_id = '{$player_id}'")->fetch(PDO::FETCH_ASSOC);


if($coPlayer2){

//echo "DAHA ÖNCEDEN DE VAR<br />";
  echo '{"result":"1y"}';

}else{


$query = $db->prepare("INSERT INTO not_registered SET
player_id = ?,
songiris = ?");
$insert = $query->execute(array(
     $player_id, $suan
));

if($insert){
  echo '{"result":"1z"}';
}else{
  echo '{"result":"0z"}';
}

//ECHO "YOKMUS EKLEDİK<br />";

}


	//echo '{"result":"0"}';
	header("Location: index.php");
}












?>