-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgsm.php
More file actions
82 lines (69 loc) · 2.27 KB
/
gsm.php
File metadata and controls
82 lines (69 loc) · 2.27 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
class Location{
public $lat;
public $lon;
public $range;
public $url;
public $failed;
public $error;
};
function MSLquery($mcc, $mnc, $lac, $ci, $sig) {
global $MSLkey;
$Loc = new Location();
$MSLUrl = "https://location.services.mozilla.com/v1/geolocate";
$MSLUrl = $MSLUrl . "?key=$MSLkey";
$MSLBody = json_encode(
array (
'cellTowers' => array (array(
'radioType' => "gsm",
'mobileCountryCode' => "$mcc",
'mobileNetworkCode' => "$mnc",
'locationAreaCode' => "$lac",
'cellId' => "$ci",
'signalStrength' => "$sig"
))
)
);
$MSLOpts = array(
'http'=>array(
'method' => "POST",
'content' => $MSLBody
)
);
$MSLcontext = stream_context_create($MSLOpts);
$MSLjson = file_get_contents($MSLUrl,false,$MSLcontext);
//$MSLjson = file_get_contents($MSLUrl);
if ($MSLjson === FALSE) {
$Loc->failed = TRUE;
$Loc->error = "<h3>Failed MSL request $MSLUrl </h3></br><div>$MSLBody</div>";
$Loc->error .= "<div>".print_r($http_response_header[0],TRUE)."</div>";
} else {
$MSLjsonRsp = json_decode($MSLjson);
$Loc->lat = $MSLjsonRsp->location->lat;
$Loc->lon = $MSLjsonRsp->location->lng;
$Loc->range = $MSLjsonRsp->accuracy;
};
return $Loc;
}
function OpenCellIDquery($mcc, $mnc, $lac, $ci, $sig) {
global $OpenCellIDkey;
$Loc = new Location();
$openCellUrl = 'http://opencellid.org/cell/get';
$openCellUrl = $openCellUrl . "?key=$OpenCellIDkey&radio=GSM&format=xml";
$openCellUrl = $openCellUrl . "&mcc=$mcc";
$openCellUrl = $openCellUrl . "&mnc=$mnc";
$openCellUrl = $openCellUrl . "&lac=$lac";
$openCellUrl = $openCellUrl . "&cellid=$ci";
$OpenCellXML = file_get_contents($openCellUrl);
if ($OpenCellXML === FALSE) {
$Loc->failed = TRUE;
$Loc->error = "<h3>Failed OpenCellID request </h3><a href=$openCellUrl>$openCellUrl</a><div>".print_r($http_response_header[0],TRUE)."</div>";
} else {
$OpenXmlRsp = new SimpleXMLElement($OpenCellXML);
$Loc->lat = $OpenXmlRsp->cell[0]['lat'];
$Loc->lon = $OpenXmlRsp->cell[0]['lon'];
$Loc->range = $OpenXmlRsp->cell[0]['range'];
}
return $Loc;
}
?>