Labs, PHP Tricks
GeoPlugin ile Yapabilecekleriniz
Merhaba,
- PHP ziyaret eden kişinin IP Adresini almamıza olanak sağlıyor.
<?php // PHP code to extract IP function getVisIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) { return $_SERVER['HTTP_CLIENT_IP']; } else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { return $_SERVER['HTTP_X_FORWARDED_FOR']; } else { return $_SERVER['REMOTE_ADDR']; } } // Store the IP address $vis_ip = getVisIPAddr(); ?>
- Aldığımız kişinin IP adresine göre ülkesini öğrenmemizin birkaç farklı yöntemi var biz Geoplugin kullanacağız.
<?php // PHP code to obtain country, city, // continent, etc using IP Address $ipdat = @json_decode(file_get_contents( "http://www.geoplugin.net/json.gp?ip=" . $vis_ip)); $vis_country = $ipdat->geoplugin_countryName; $vis_city = $ipdat->geoplugin_city; $vis_lat = $ipdat->geoplugin_latitude; $vis_long = $ipdat->geoplugin_longitude; $vis_timezone = $ipdat->geoplugin_timezone; ?>
- Örnek Kullanım #1: Ziyaretçi Türkiye'den Bağlandıysa:
<?php if ( $vis_country == 'Turkey' ) { ?> <h2>Hoşgeldiniz!</h2> <p>Selam, Benim adım <b>Hakkı Cengiz</b>. Websiteme hoşgeldiniz :) Burada bazen makale yazarım ve yaptığım işleri sergilerim. Ayrıca şarkılar, alıntı sözler, dizi & film önerileri bulabilirsin. Eğer hayallerini kodlama da yardıma ihtiyaç duyarsan, iletisim (@) hakkicengiz.com. <br><span style="color: #2196f3">Genç Girişimci</span> ● <span style="color: #2196f3">Wordpress & Frontend Developer</span> ﴾ #flux ♥ #hakkicengiz7 ﴿</p> <?php } else { ?> <h2>Welcome!</h2> <p>Hey, I'm <b>Hakkı Cengiz</b>. Welcome to my website :) Sometimes I write essays and show my works here. Also you'll find songs, quotes, movie & serie suggestions on Passion. If you need help for coding your dreams, iletisim (@) hakkicengiz.com. <br><span style="color: #2196f3">Young Entrepreneur</span> ● <span style="color: #2196f3">Wordpress & Frontend Developer</span> ﴾ #flux ♥ #hakkicengiz7 ﴿</p> <?php } ?>
- Örnek Kullanım #2: Converter
Dolar bazlı ($) veya Euro bazlı satılan ürünlerin ₺ ye göre ne kadar ettiğini gösterebiliriz.
Örnek
İncelediklerim:
- HTML5 Geolocation & PHP
- Google Geocoding
- Geolocator PHP
- StackOverFlow
- IPInfoDB
Henüz yorum eklenmemiş.