• 14-08-2020, 17:00:16
    #1
    Önce kullanıcının ip adresini çekelim: $ip = $_SERVER['REMOTE_ADDR'];şimdi fonksyionu ekleyelim:
    function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) {$output = NULL;if(filter_var($ip, FILTER_VALIDATE_IP) === FALSE) {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","TR" => "Türkiye",);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 "city":$output = @$ipdat->geoplugin_city;break;case "countrycode":$output = @$ipdat->geoplugin_countryCode;break;}}}return $output;}artık ülkeyi ve şehri görebiliriz:
    echo $ulke = ip_info($ip, "Country Code");echo $sehir = ip_info($ip, "City");

    Arkadaşlar 2 gün önce kişisel site kurdum ve blog bölümü ekledim. Wordpress makale yazımını uzun zamandır yapmadığım için daha önce yaptığım basit şeylerle ilgili konular paylaşarak keşfetmeye çalıştım. Bu konuda onlardan biri. Hem burada hazır kod bankasında dursun isteyenler direkt ulaşabilsin hem de öneriler alabileyim istedim bu yüzden buraya da konuyu açtım.
    Konuyu aşağıdaki linkten inceleyebilirsiniz. Yazım tarzım, başlık şekilleri vs vs her türlü önerilerinize de açığım genel yazım şeklim hakkında vs buradan yorum olarak, makaledeki anlatımda sorun yaşarsanız onları da sitemden yorum olarak bildirirseniz çok sevinirim. Umarım konu da yararlı olmuştur ve işinize yarar
    İleriki zamanlarda da tema, admin paneli vs üretirken karşılaştığım hataların çözümlerini ve sürekli kullandığım kod bloklarını vs paylaşmayı düşünüyorum

    Kaynak Linki: PHP ile Kullanıcıdan Onay Almadan Ülke ve Şehrine Erişme
  • 14-08-2020, 17:02:47
    #2
    Teşekkürler.
  • 14-08-2020, 17:06:36
    #3
    actionmax34 adlı üyeden alıntı: mesajı görüntüle
    Teşekkürler.
    Ben teşekkür ederim hocam umarım işinize yarar
  • 14-08-2020, 17:13:22
    #4
    İçeriğin tamamını buraya yazıp altına kaynak linkini eklemeniz daha iyi olacaktır
  • 14-08-2020, 17:15:11
    #5
    Sinan Yorulmaz adlı üyeden alıntı: mesajı görüntüle
    İçeriğin tamamını buraya yazıp altına kaynak linkini eklemeniz daha iyi olacaktır
    Tamam hocam düzenliyorum teşekkürler
  • 14-08-2020, 17:16:41
    #6
    Böyle bir şeye ihtiyacım vardı teşekkürler. Tam inceleyemiyorum şu an, il plaka kodunu veriyor mu? % kaç oranla doğru biliyor?
  • 14-08-2020, 17:18:11
    #7
    berkaycatak adlı üyeden alıntı: mesajı görüntüle
    Böyle bir şeye ihtiyacım vardı teşekkürler. Tam inceleyemiyorum şu an, il plaka kodunu veriyor mu? % kaç oranla doğru biliyor?
    ben hiç hatalı olduğunu görmedim, il plaka kodunu bilmiyorum ama il ismini veriyor. İl ismine göre plaka koduna çevirtebilirsiniz ama plaka kodu veriyor mu bakıyım bi

    edit: veriyormuş hocam bi deneyeyim çektiğimde özelden size atarım sonra sitedeki konuya ekleyip içeriği buraya da taşırım
  • 14-08-2020, 17:45:04
    #8
    Bende kendi kullanmış olduğum kod parçasını buraya ekliyorum işinize yarar belki

    index.php
    <?php
    require_once('class.php');
    
    $geoplugin = new geoPlugin();
    $geoplugin->locate();
    
    echo "Coğrafi konum sonuçları: {$geoplugin->ip}: <br />\n".
        "Şehir: {$geoplugin->city} <br />\n".
        "İl: {$geoplugin->region} <br />\n".
        "Plaka Kodu: {$geoplugin->regionCode} <br />\n".
        "Bölge Adı: {$geoplugin->regionName} <br />\n".
        "Ülke Adı: {$geoplugin->countryName} <br />\n".
        "Ülke Kodu: {$geoplugin->countryCode} <br />\n".
        "Saat Dilimi: {$geoplugin->timezone} <br />\n".
        "Para Birimi: {$geoplugin->currencyCode} <br />\n".
        "Para Birimi Sembolü: {$geoplugin->currencySymbol} <br />\n";
    
    if ( $geoplugin->currency != $geoplugin->currencyCode ) {
        echo "" . $geoplugin->convert(100) ." </p>\n";
    }
    
    $nearby = $geoplugin->nearby();
    
    
    ?>
    class.php
    <?php
    
    class geoPlugin {
        
        var $host = 'http://www.geoplugin.net/php.gp?ip={IP}&base_currency={CURRENCY}&lang={LANG}';
            
        //Para Birimi
        var $currency = 'TRY';
        
        //    Varsaylan Dil
        var $lang = 'tr';
    /*
    Desteklenen Diller:
    de
    en
    es
    fr
    ja
    pt-BR
    ru
    zh-CN
    */
    
        var $ip = null;
        var $city = null;
        var $region = null;
        var $regionCode = null;
        var $regionName = null;
        var $dmaCode = null;
        var $countryCode = null;
        var $countryName = null;
        var $inEU = null;
        var $euVATrate = false;
        var $continentCode = null;
        var $continentName = null;
        var $latitude = null;
        var $longitude = null;
        var $locationAccuracyRadius = null;
        var $timezone = null;
        var $currencyCode = null;
        var $currencySymbol = null;
        var $currencyConverter = null;
        
        function __construct() {
    
        }
        
        function locate($ip = null) {
            
            global $_SERVER;
            
            if ( is_null( $ip ) ) {
                $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
                //CloudFire Kullanıyorsanız burayı Açın //$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
            }
            
            $host = str_replace( '{IP}', $ip, $this->host );
            $host = str_replace( '{CURRENCY}', $this->currency, $host );
            $host = str_replace( '{LANG}', $this->lang, $host );
            
            $data = array();
            
            $response = $this->fetch($host);
            
            $data = unserialize($response);
            
            $this->ip = $ip;
            $this->city = $data['geoplugin_city'];
            $this->region = $data['geoplugin_region'];
            $this->regionCode = $data['geoplugin_regionCode'];
            $this->regionName = $data['geoplugin_regionName'];
            $this->dmaCode = $data['geoplugin_dmaCode'];
            $this->countryCode = $data['geoplugin_countryCode'];
            $this->countryName = $data['geoplugin_countryName'];
            $this->inEU = $data['geoplugin_inEU'];
            $this->euVATrate = $data['euVATrate'];
            $this->continentCode = $data['geoplugin_continentCode'];
            $this->continentName = $data['geoplugin_continentName'];
            $this->latitude = $data['geoplugin_latitude'];
            $this->longitude = $data['geoplugin_longitude'];
            $this->locationAccuracyRadius = $data['geoplugin_locationAccuracyRadius'];
            $this->timezone = $data['geoplugin_timezone'];
            $this->currencyCode = $data['geoplugin_currencyCode'];
            $this->currencySymbol = $data['geoplugin_currencySymbol'];
            $this->currencyConverter = $data['geoplugin_currencyConverter'];
            
        }
        
        function fetch($host) {
    
            if ( function_exists('curl_init') ) {
                            
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $host);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_USERAGENT, 'geoPlugin PHP Class v1.1');
                $response = curl_exec($ch);
                curl_close ($ch);
                
            } else if ( ini_get('allow_url_fopen') ) {
                
                $response = file_get_contents($host, 'r');
                
            } else {
    
                trigger_error ('geoPlugin class Error: Cannot retrieve data. Either compile PHP with cURL support or enable allow_url_fopen in php.ini ', E_USER_ERROR);
                return;
            
            }
            
            return $response;
        }
        
        function convert($amount, $float=2, $symbol=true) {
            
            if ( !is_numeric($this->currencyConverter) || $this->currencyConverter == 0 ) {
                trigger_error('geoPlugin class Notice: currencyConverter has no value.', E_USER_NOTICE);
                return $amount;
            }
            if ( !is_numeric($amount) ) {
                trigger_error ('geoPlugin class Warning: The amount passed to geoPlugin::convert is not numeric.', E_USER_WARNING);
                return $amount;
            }
            if ( $symbol === true ) {
                return $this->currencySymbol . round( ($amount * $this->currencyConverter), $float );
            } else {
                return round( ($amount * $this->currencyConverter), $float );
            }
        }
        
        function nearby($radius=10, $limit=null) {
    
            if ( !is_numeric($this->latitude) || !is_numeric($this->longitude) ) {
                trigger_error ('geoPlugin class Warning: Incorrect latitude or longitude values.', E_USER_NOTICE);
                return array( array() );
            }
            
            $host = "http://www.geoplugin.net/extras/nearby.gp?lat=" . $this->latitude . "&long=" . $this->longitude . "&radius={$radius}";
            
            if ( is_numeric($limit) )
                $host .= "&limit={$limit}";
                
            return unserialize( $this->fetch($host) );
    
        }
    
        
    }
    
    ?>