Jump to content
php.lv forumi

valsts noteikšana pēc IP


anonīms

Recommended Posts

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

Link to comment
Share on other sites

  • 2 months later...

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?

Link to comment
Share on other sites

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 by anonīms
Link to comment
Share on other sites

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
}
?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...