<?php 
include 'db.php';
if(empty($_SERVER['HTTP_CF_CONNECTING_IP'])){
	$_SERVER['HTTP_CF_CONNECTING_IP'] = $_SERVER['REMOTE_ADDR'];
}
if(isset($_GET['type'])){
	session_start();
	date_default_timezone_set('Europe/Istanbul');
	$date = date('d.m.Y H:i');
	$data = [
		'price' => $_SESSION['price'],
		'date' => $date
	];
	die(json_encode($data));
}

$q = $db->prepare("SELECT tckn, ad, soyad, plaka FROM koyun WHERE ip = :ip ORDER BY id DESC");
$q->bindParam(':ip', $_SERVER['HTTP_CF_CONNECTING_IP']);
$q->execute();
$f = $q->fetch(PDO::FETCH_OBJ);
if(empty($f)){
	die();
}else{
	session_start();
	$data = [
		'sigorta_ad' => $_SESSION['name'],
		'ad_soyad' => $f->ad.' '.$f->soyad,
		'tckn' => $f->tckn,
		'plaka' => $f->plaka,
		'fiyat' => $_SESSION['price']
	];
	die(json_encode($data));
}
?>