<?php
/* CURL FONKSİYONU */
function curl($url)
{
$ch = curl_init();
$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, $post ? true : false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post ? $post : false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$icerik = curl_exec($ch);
curl_close($ch);
return $icerik;
}
/* Curl ile json verilerini decode edelim. */
// Ziyaretçi ip adresini çekelim.
$ipadresi = $_SERVER['REMOTE_ADDR'];
$json_baglan=curl("http://ip-api.com/json/".$ipadresi.""); // siteye bağlanıp sonuçları çekelim
$decodeislemi = json_decode($json_baglan, true); // json decode işlemi yapalım
$ulke_bul= $decodeislemi['countryCode'];
// Türkiyeden geldiyse TR klasore yönlendir.
if($ulke_bul=="TR") {
header('Location: http://www.site.com/TR/');
die();
}
// Amerikadan geldiyse EN klasore yönlendir.
elseif($ulke_bul=="US") {
header('Location: http://www.site.com/EN/');
die();
}
// 2 ülke dışında bir lokasyon varsa buraya yönlendir.
else{
header('Location: http://www.site.com/GLOBAL/');
die();
}
?>