-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
63 lines (59 loc) · 1.11 KB
/
api.php
File metadata and controls
63 lines (59 loc) · 1.11 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
//载入纯真IP
include_once( 'qqwry.php' );
$ip = $_GET['ip']; //获取IP
$type = $_GET['type']; //获取数据类型
$data = $_GET['data']; //要返回的数据
//如果IP不存在或者为空
if((!isset($ip) || ($ip == ''))) {
//获取访客IP
$ip = $_SERVER["REMOTE_ADDR"];
}
//如果IP格式不对
if(!filter_var($ip, FILTER_VALIDATE_IP)) {
$reinfo = array(
"status" => 0,
"msg" => 'IP格式不对'
);
echo json_encode($reinfo);
exit;
}
//查询IP
$qqwry = new ip();
$addr = $qqwry -> ip2addr("$ip");
$addr = array_slice($addr,2,4);
$addr = implode(" ",$addr);
//返回不同的数据
switch ( $data )
{
case 'ip':
$addr = '';
break;
case 'addr':
$ip = '';
break;
default:
$ip = $ip;
$addr = $addr;
break;
}
//根据类型返回不同结果
switch ( $type )
{
case 'text':
echo $ip." ".$addr;
break;
case 'json':
$info = array(
"status" => 1,
"ip" => $ip,
"addr" => $addr
);
echo json_encode($info);
exit;
default:
echo $ip." ".$addr;
break;
}
?>