anonīms Posted September 20, 2010 Report Share Posted September 20, 2010 Pagooglēju un interesi izrāda GEO IP kods. Vai tas būtu tas labākais un vēlāms arī ātrākais variants vai tomēr to varētu panākt arī savādāk? Source: http://www.go4expert.com/forums/showthread.php?t=3511 Quote Link to comment Share on other sites More sharing options...
marrtins Posted September 20, 2010 Report Share Posted September 20, 2010 Savādāk: http://ip2country.hackers.lv/api/ip2country?ip=11.12.13.14,21.22.23.24 Pluss - var čekot uzreiz ļoti lielu kaudzi ar IP, ļoti labā ātrumā. Quote Link to comment Share on other sites More sharing options...
anonīms Posted September 20, 2010 Author Report Share Posted September 20, 2010 Paldies, bet ir viens BET. Man nav nekādas jausmas kā rīkoties tālāk. Ja šis http://ip2country.hackers.lv/api/ip2country?ip=<mana ip> būtu uz mana hosta, tad nebūtu nekādu problēmu, bet kā ir iespēja iegūt visus getu, ja urla nav personīgā, bet no citas lapas? Un vai tas maz ir iespējams. Paskatījos to JSON, bet tāpat netiku skaidrs. Varbūt ir iespēja, ka iemetat mazu, mazu piemēru kā to get variabli dabūt? Paldies Quote Link to comment Share on other sites More sharing options...
marrtins Posted September 20, 2010 Report Share Posted September 20, 2010 $data = json_decode(file_get_contents("http://ip2country.hackers.lv/api/ip2country?ip=ip1,ip2,ipN")); print_r($data) Ja vajadzīgs liels apjoms, tad POST ar curl (ir pilns nets ar piemēriem) Quote Link to comment Share on other sites More sharing options...
anonīms Posted September 20, 2010 Author Report Share Posted September 20, 2010 okey, paldies Quote Link to comment Share on other sites More sharing options...
anonīms Posted November 29, 2010 Author Report Share Posted November 29, 2010 Es laikam esmu stulbs. Nu nesanāk man izvilkt. $data = json_decode(file_get_contents("http://ip2country.hackers.lv/api/ip2country?ip={$ip}"),TRUE); print_r($data); echo $data[$ip]; Array ( [c] => Array ( [159.148.86.242] => LV ) ) kā man īsti dabūt ārā to LV? Quote Link to comment Share on other sites More sharing options...
marcis Posted November 29, 2010 Report Share Posted November 29, 2010 lol echo $data['c'][$ip]; Quote Link to comment Share on other sites More sharing options...
codez Posted November 29, 2010 Report Share Posted November 29, 2010 domāju, ka anonīma atrastais variants strādās par pāris kārtām ātrāk un aplikācija būs neatkarīga no sveša servisa. Quote Link to comment Share on other sites More sharing options...
anonīms Posted November 29, 2010 Author Report Share Posted November 29, 2010 (edited) Tēma cita, bet tas pats kods. Kā parbaudīt vai iedotais $_GET['c'] vispār ir iekšs array? itkā izmantoju in_array, bet tomēr kods gļuko un paņemot LV rāda, ka šāda valsts nav sarakstā. $data = json_decode(file_get_contents("http://ip2country.hackers.lv/api/ip2country?ip={$ip}"),TRUE); if($data['c'][$ip] != $_GET['c']) $wrong_country = true; if(!$_GET['c'] OR $_GET['c'] AND $wrong_country OR $_GET['c'] AND !in_array($ip,$countries)) { echo '<div id="reg_bg">'; //---------------<-------------- Valstu parbaudes if(!in_array($ip,$countries)) echo '<div class="error">'.$lang['reg_no_country'].'</div>'; if($wrong_country) echo '<div class="error">'.$lang['reg_wrong_country'].'</div>'; //--------------->-------------- Valstu parbaudes echo '<div class="info">'.$lang['reg_choose1'].'</div>'; //---------------<-------------- Countries list $countries = array( 'Latvia'=>'LV', 'Lithuania'=>'LT', 'Estonia'=>'EE', 'United Kindom'=>'UK', 'Ireland'=>'IE', 'Germany'=>'DE', 'Norway'=>'NO', 'Sweden'=>'SE', 'Finland'=>'FI', 'Russia'=>'RU', 'Belarus'=>'BY'); echo '<ul id="countries_list">'; foreach($countries AS $country=>$flag) { echo '<li><a href="/registration/'.$flag.'/"><img src="/public/images/flags/'.strtolower($flag).'.png" alt="" /> '.$country.'</a></li>'; } echo '</ul>'; //--------------->-------------- Countries list echo '</div>'; //reg_bg } codez. Kods tiek izmantots tikai vienā vietā, takā īsti jēga nav dēļ tā turēt visu pie sevis. Tikai reģistrācijas procesā Edited November 29, 2010 by anonīms Quote Link to comment Share on other sites More sharing options...
Kavacky Posted November 29, 2010 Report Share Posted November 29, 2010 Nu ja tu nodefinētu $countries PIRMS pārbaudīt, vai tur kaut kas ir iekšā, tad varētu arī darboties. Quote Link to comment Share on other sites More sharing options...
Val Posted November 29, 2010 Report Share Posted November 29, 2010 $wrong_country arī vajadzētu defaulto vērtību uzstādīt. Labāk apstāsti, ko vēlies iekš pirmā IF panākt. No kurienes uzrodas $ip mainīgais? Quote Link to comment Share on other sites More sharing options...
anonīms Posted November 29, 2010 Author Report Share Posted November 29, 2010 aga. Bik sajaucos. <?php $data = json_decode(file_get_contents("http://ip2country.hackers.lv/api/ip2country?ip={$ip}"),TRUE); if($_GET['c'] AND $data['c'][$ip] != $_GET['c']) $wrong_country = true; else $wrong_country = false; $countries = array( 'Latvia'=>'LV', 'Lithuania'=>'LT', 'Estonia'=>'EE', 'United Kindom'=>'UK', 'Ireland'=>'IE', 'Germany'=>'DE', 'Norway'=>'NO', 'Sweden'=>'SE', 'Finland'=>'FI', 'Russia'=>'RU', 'Belarus'=>'BY'); if(!$_GET['c'] OR $_GET['c'] AND $wrong_country OR $_GET['c'] AND !in_array($_GET['c'],$countries)) { echo '<div id="reg_bg">'; //---------------<-------------- Valstu parbaudes if(!in_array($_GET['c'],$countries) AND $_GET['c']) echo '<div class="error">'.$lang['reg_no_country'].'</div>'; if($wrong_country AND in_array($_GET['c'],$countries)) echo '<div class="error">'.$lang['reg_wrong_country'].'</div>'; //--------------->-------------- Valstu parbaudes echo '<div class="info">'.$lang['reg_choose1'].'</div>'; //---------------<-------------- Countries list echo '<ul id="countries_list">'; foreach($countries AS $country=>$flag) { echo '<li><a href="/registration/'.$flag.'/"><img src="/public/images/flags/'.strtolower($flag).'.png" alt="" /> '.$country.'</a></li>'; } echo '</ul>'; //--------------->-------------- Countries list echo '</div>'; //reg_bg } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.