Şimdi Ara

Php ve Json ile konum bilgisi nasıl alınır ?

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
1
Cevap
0
Favori
520
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • Merhaba,

    Iletisim Formuna mesaj gönderen müşterilerin ip adresinden konum bilgisini bulan bir fonksiyon yazdım dbip sitesinin json apisinden faydalandim ama çalışmıyor,php hata da vermiyor, daha önce netip.den buldugum calismisti ama bazen yanlış konum bilgisi veriyordu.



    Bir yardimci olur musunuz ?

    Kod :
    <?php
    error_reporting(1);
    $ip = $_SERVER['REMOTE_ADDR'];

    $json =file_get_contents('http://api.db-ip.com/addrinfo?addr='. $ ip.'&api_key=150d4cf09c200ee591744b4d68890abf87e7f1a7');
    $data = json_decode($data,true);
    $ulke = $data ['country'][0] ;
    $il = $data ['city'][0];
    $ilce= $data ['country'][0];


    echo "<pre>";

    print_r ($ulke);
    print_r ($il);
    print_r ($ilce);

    exit;

    ?>

    Jsondan gelen veri :

    {"address":"8.8.8.8","country":"US","stateprov":"California","city":"Mountain View"}



    Onceki fonksiyon :

    <?php
    function geoCheckIP($ip)

    {

    //check, if the provided ip is valid

    if(!filter_var($ip, FILTER_VALIDATE_IP))

    {

    throw new InvalidArgumentException("IP adresi gecersiz");

    }

    //contact ip-server

    $response=@file_get_contents('http://www.netip.de/search?query='.$ip);

    if (empty($response))

    {

    throw new InvalidArgumentException("Konum Bulma Basarisiz !!");

    }

    //Array containing all regex-patterns necessary to extract ip-geoinfo from page

    $patterns=array();

    $patterns["domain"] = '#Domain: (.*?) #i';

    $patterns["country"] = '#Country: (.*?) #i';

    $patterns["state"] = '#State/Region: (.*?)<br#i';

    $patterns["town"] = '#City: (.*?)<br#i';

    //Array where results will be stored

    $ipInfo=array();


    //check response from ipserver for above patterns

    foreach ($patterns as $key => $pattern)

    {

    //store the result in array

    $ipInfo[$key] = preg_match($pattern,$response,$value) && !empty($value[1]) ? $value[1] : '..';

    }
    /*I've included the substr function for Country to exclude the abbreviation (UK, US, etc..)
    To use the country abbreviation, simply modify the substr statement to:
    substr($ipInfo["country"], 0, 3)
    */
    $ipdata = $ipInfo["town"]. ", ".$ipInfo["state"].", ".substr($ipInfo["country"], 4);

    return $ipdata;

    }

    ?>



    < Bu mesaj bu kişi tarafından değiştirildi prodog -- 1 Mayıs 2015; 17:08:21 >
    < Bu ileti mobil sürüm kullanılarak atıldı >







  • Yapay Zeka’dan İlgili Konular
    Daha Fazla Göster
    
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.