function getByIp ip DBHost localhost DBLogin plasters DBPassword 07b66

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function getByIp($ip){
$DBHost = 'localhost';
$DBLogin = 'plasters';
$DBPassword = '07b66adedcc2';
$DBName = 'plasters';
$conn = mysql_connect ($DBHost, $DBLogin, $DBPassword)
or die ("Соединение не установлено!");
mysql_query("SET NAMES 'utf8'");
$res = mysql_db_query($DBName, "SELECT * FROM `ip_database` WHERE `LEFT_IP` <= ".sprintf("%u", ip2long($ip))." AND `RIGHT_IP` >= ".sprintf("%u", ip2long($ip)));
if($item = mysql_fetch_assoc($res)){
$cities = mysql_db_query($DBName, "SELECT * FROM `ip_cities` WHERE `CITY_ID` = ".$item['CITY']);
$city = mysql_fetch_assoc($cities);
$countries = mysql_db_query($DBName, "SELECT * FROM `ip_countries` WHERE `ALPHA2` = '".$item['COUNTRY']."'");
$country = mysql_fetch_assoc($countries);
$info = array(
'COUNTRY_NAME' => $country['NAME'],
'COUNTRY_FULL_NAME' => $country['FULL_NAME'],
'COUNTRY_EN_NAME' => $country['NAME_EN'],
'CITY_NAME' => $city['NAME'],
'AREA' => $city['AREA'],
'DISTRICT' => $city['DISTRICT'],
'CITY_LAT' => $city['LAT'],
'CITY_LNG' => $city['LNG']
);
return $info;
}
else return false;
mysql_close($conn);
}