php ile birden fazla ülkeden girişi engellemek?
3
●461
- 24-05-2010, 02:12:43belirlediğin ülkelerden giriş yapılmasını diğer tüm ülkeleri bloklamak istiyorsan aşağıdakini kullanabilirsin. (örnek türkiye içindir)sLaviaN adlı üyeden alıntı: mesajı görüntüle
diğer ülke iplerini http://www.countryipblocks.net/ adresinde bulabilirsin.
<?php function Turk_mu($url_csv){ $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $url_csv); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); $str_fromfile = curl_exec($curl_handle); curl_close($curl_handle); $range = explode("\n", $str_fromfile); $ip_addr = getenv(REMOTE_ADDR); //gets the IP of the visitor $ip_byte = explode('.', $ip_addr); $ip_number = (16777216 * (int) $ip_byte[0]) + (65536 * (int) $ip_byte[1]) + (256 * (int) $ip_byte[2]) + ((int) $ip_byte[3]); for($i = 0; $range[$i] != NULL && $is_positive == NULL; $i++){ // the condition $line[$i] != NULL means that you should not put blank lines before the end of your CSV. The values should start at line 1. $range[$i] = rtrim(ltrim($range[$i])); //you may remove this if you are sure the CSV doesnt contain whitespaces $ends_addr = explode(',', $range[$i]); //for CSV (comma-separated values), comma is the separator. You may change this if your TXT uses different separator. $ends_addr[0] = rtrim($ends_addr[0]); //again, you may remove this if your CSV is free from whitespaces $ends_addr[1] = ltrim($ends_addr[1]); //yet, again $start_ip_byte = explode('.', $ends_addr[0]); $end_ip_byte = explode('.', $ends_addr[1]); $start_ip_number = (16777216 * (int) $start_ip_byte[0]) + (65536 * (int) $start_ip_byte[1]) + (256 * (int) $start_ip_byte[2]) + ((int) $start_ip_byte[3]); $end_ip_number = (16777216 * (int) $end_ip_byte[0]) + (65536 * (int) $end_ip_byte[1]) + (256 * (int) $end_ip_byte[2]) + ((int) $end_ip_byte[3]); if($ip_number >= $start_ip_number && $ip_number <= $end_ip_number) $is_positive = 1; } if($is_positive == 1) return true; else return false; } if(Turk_mu('http://test.divxklip.net/turkey.txt') === true) echo 'Turkiye Ziyaretci'; ?>