-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_lib.php
More file actions
70 lines (51 loc) · 1.65 KB
/
_lib.php
File metadata and controls
70 lines (51 loc) · 1.65 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
<?php
/**********************************************************************
* Author: Arun Vijayan (arunvijayan[]gmail.com)
* Web...: http://www.webforth.com/handsetdetect
* Name..: HandSetDetect
* Desc..: Handset Detection API client.
*
*/
class HandsetDetect{
var $apikey;
var $hd_server;
function __construct($apikey, $hd_server){
$this->apikey = $apikey;
$this->hd_server = $hd_server;
}
// Using JSON. You can use XML also if you want.
function sendjson($data, $url) {
$data['apikey'] = $this->apikey;
$tmp = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $tmp);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
$reply = curl_exec($ch);
$ch = null;
return json_decode($reply, true);
}
// Detect the handset device
function DetectDevice(){
$data = array();
$data['User-Agent'] = $_SERVER['HTTP_USER_AGENT'];
$data['ipaddress'] = $_SERVER['REMOTE_ADDR'];
$data['options'] = "geoip, product_info, display";
// Sometimes this doesnt work
//$data = array_merge ($data, $_SERVER);
return $this->sendjson($data, $this->hd_server."/devices/detect.json");
}
// Fetch a list of vendors
function GetVendorList() {
$data = array();
return $this->sendjson($data, $this->hd_server."/devices/vendors.json");
}
// Fetch a list of all models for a given vendor
function GetDeviceModels($vendor) {
$data = array();
$data['vendor'] = $vendor;
return $this->sendjson($data, $this->hd_server."/devices/models.json");
}
}// end HandsetDetect class
?>