Merhaba;
Aşağıda ki kod ile istenilen ülke engellenebiliyor ama ek olarak ŞEHİR engellemesi eklemek istiyorum ama yapamadım. Yardımcı olabilir misiniz acaba? Birçok forum gibi yerlere sordum ama net cevaplar alamıyorum henüz, burayı ilk defa keşfettim umarım daha tanınır hale gelir.
Ne yapacağımı, yani kod' ta ne gibi düzenleme yapacağımı belirtir misiniz acaba.
function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {
$output = NULL;
if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) {
$ip = $_SERVER["REMOTE_ADDR"];
if ($deep_detect) {
if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP))
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP))
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
}
$purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose)));
$support = array("country", "countrycode", "state", "region", "city", "location", "address");
$continents = array(
"AF" => "Africa",
"AN" => "Antarctica",
"AS" => "Asia",
"EU" => "Europe",
"OC" => "Australia (Oceania)",
"NA" => "North America",
"SA" => "South America"
);
if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) {
$ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip));
if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) {
switch ($purpose) {
case "location":
$output = array(
"city" => @$ipdat->geoplugin_city,
"state" => @$ipdat->geoplugin_regionName,
"country" => @$ipdat->geoplugin_countryName,
"country_code" => @$ipdat->geoplugin_countryCode,
"continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)],
"continent_code" => @$ipdat->geoplugin_continentCode
);
break;
case "address":
$address = array($ipdat->geoplugin_countryName);
if (@strlen($ipdat->geoplugin_regionName) >= 1)
$address[] = $ipdat->geoplugin_regionName;
if (@strlen($ipdat->geoplugin_city) >= 1)
$address[] = $ipdat->geoplugin_city;
$output = implode(", ", array_reverse($address));
break;
case "city":
$output = @$ipdat->geoplugin_city;
break;
case "state":
$output = @$ipdat->geoplugin_regionName;
break;
case "region":
$output = @$ipdat->geoplugin_regionName;
break;
case "country":
$output = @$ipdat->geoplugin_countryName;
break;
case "countrycode":
$output = @$ipdat->geoplugin_countryCode;
break;
}
}
}
return $output;
}
// Engellenecek ülkelerin Country Kod'larını aşağıdaki array içine ekleyebilirsiniz
// 2 Harfli ISO kodlarını buradan bulabilirsiniz: https://www.nationsonline.org/oneworld/country_code_list.htm
$engelli_ulke_kodlari=array("AF"=>0, "AX"=>0, "AL"=>0, "DZ"=>0, "AS"=>0,"AD"=>0,"AO"=>0,"AI"=>0,"AQ"=>0,"AG"=>0,"AR"=>0,"AM"=>0,"AW"=>0,"AU"=>0,"AT"=>0,"AZ"=>0,"BS"=>0,"BH"=>0,"BD"=>0,"BB"=>0,"BY"=>0,"BE"=>0,"BZ"=>0,"BJ"=>0,"BM"=>0,"BT"=>0,"BO"=>0,"BQ"=>0,"BA"=>0,"BW"=>0,"BV"=>0,"BR"=>0,"IO"=>0,"BN"=>0,"BG"=>0,"BF"=>0,"BI"=>0,"KH"=>0,"CM"=>0,"CA"=>0,"CV"=>0,"KY"=>0,"CF"=>0,"TD"=>0,"CL"=>0,"CN"=>0,"CX"=>0,"CC"=>0,"CO"=>0,"KM"=>0,"CG"=>0,"CD"=>0,"CK"=>0,"CR"=>0,"CI"=>0,"HR"=>0,"CU"=>0,"CW"=>0,"CY"=>0,"CZ"=>0,"DK"=>0,"DJ"=>0,"DM"=>0,"DO"=>0,"EC"=>0,"EG"=>0,"SV"=>0,"GQ"=>0,"ER"=>0,"EE"=>0,"ET"=>0,"FK"=>0,"FO"=>0,"FJ"=>0,"FI"=>0,"FR"=>0,"GF"=>0,"PF"=>0,"TF"=>0,"GA"=>0,"GM"=>0,"GE"=>0,"DE"=>0,"GH"=>0,"GI"=>0,"GR"=>0,"GL"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=>0,"CH"=>0,"SY"=>0,"TW"=>0,"TJ"=>0,"TZ"=>0,"TH"=>0,"TL"=>0,"TG"=>0,"TK"=>0,"TO"=>0,"TT"=>0,"TN"=>0,"TM"=>0,"TC"=>0,"TV"=>0,"UG"=>0,"UA"=>0,"AE"=>0,"GB"=>0,"US"=>0,"UM"=>0,"UY"=>0,"UZ"=>0,"VU"=>0,"VE"=>0,"VN"=>0,"VG"=>0,"VI"=>0,"WF"=>0,"EH"=>0,"YE"=>0,"ZM"=>0,"ZW"=>0);
$ziyaretci_ulke_kodu = ip_info("Visitor", "Countrycode");
if (array_key_exists($ziyaretci_ulke_kodu,$engelli_ulke_kodlari)){
header('HTTP/1.1 403 Forbidden');
echo "Forbidden Country IP! / Yasaklı Ülke IP'si";
header("Location: https://www.google.com.tr");
die();
}