sunucuda denemeniz gerekiyor.
Eğer bilgisayarınızdaki localhostta deniyorsanız ip adresini kendiniz girmeniz gerekir.
<?php
// sunucuda çalışır.
$data = file_get_contents('http://ip-api.com/json/'.$_SERVER['REMOTE_ADDR'].'?fields=regionName');
$data = json_decode($data, true);
echo $data['regionName'];
?><?php
// localhostta çalışır
$ip = '24.48.0.1';
$data = file_get_contents('http://ip-api.com/json/'.$ip.'?fields=regionName');
$data = json_decode($data, true);
echo $data['regionName'];
?>
çok teşekkür ederim acemilik işte.
çalışıyor. yardım eden herkese teşekkürler.