function GetCountry($ip) { static $rem_ips = array(); $ipvalue = ip2value($ip); $q = "SELECT sip,eip,ctry,country FROM ip2country WHERE sip<={$ipvalue} AND eip>={$ipvalue}"; // OPTIMIZATION - remembered diapazons foreach ($rem_ips as $rem_ip) { if ($rem_ip['sip'] < $ipvalue && $rem_ip['eip'] > $ipvalue) { return array('ctry' => strtolower($rem_ip['ctry']), 'country' => $rem_ip['country']); } } // -- eof optimization $res = mysql_query($q); if (!mysql_num_rows($res)) { return false; } $res = mysql_fetch_assoc($res); // remember the retrieved IP data: $rem_ips[] = array('sip' => $res['sip'], 'eip' => $res['eip'], 'ctry' => $res['ctry'], 'country' => $res['country']); return array('ctry' => strtolower($res['ctry']), 'country' => $res['country']); }
if ($_GET['action'] == "save") { // ... foreach ($_POST['sips'] as &$sip) { $sip = ip2value($sip); } foreach ($_POST['eips'] as &$eip) { $eip = ip2value($eip); } foreach ($_POST['assigned'] as &$ass) { $ass = strtotime($ass); } $BILL->SaveDiapasons($_POST['ids'], $_POST['sips'], $_POST['eips'], $_POST['sources'], $_POST['assigned']); die("<script>document.location.href='?p={$p}&act={$act}&country={$country}';</script>"); } elseif ($_GET['action'] == "adddiap") { // ... $diap = array('sip' => ip2value($_POST['addsip']), 'eip' => ip2value($_POST['addeip']), 'source' => $_POST['addsource'], 'ctry' => $_POST['addctry'], 'cntry' => $_POST['addcntry'], 'country' => $_POST['addcountry']); $BILL->AddDiapason($diap); die("<script>document.location.href='?p={$p}&act={$act}&country={$country}';</script>"); } elseif ($_GET['action'] == "delete") { // ... $BILL->DeleteDiapason($_GET['id']); die("<script>document.location.href='?p={$p}&act={$act}&country={$country}';</script>"); } ?> <form action="<?php echo "?p={$p}&act={$act}&country={$country}&action=save"; ?> " method="post"> <table width=100% class="tbl1"> <tr> <td>ID</td>