<?php |
$data = json_decode(file_get_contents("php://input")); |
if (isset($data) && !empty($data)){ |
deviceConnection($data); |
} |
echo json_encode(array('success' =>1, 'response' => 'Device connection establised')); |
function deviceConnection($data) |
{ |
$imei = isset($data['imei']) ? $data['imei'] : “; // Getting the imei number from request |
if (!empty($imei)) { |
if ($this->checkDeviceRegistered($imei)) { // Checking the device already registered in DB |
// True |
//Do something if device already registered |
$this->logDeviceConnection($imei); // Save the request in the file |
} else { // False |
//If device is not registerd this code will execite |
$this->registerDevice($imei); // Registering/storing device information in System/DB |
$this->logNewDevice($imei); // Save the new device connection is file |
$this->notifySystemAdmin($imei); // Notifying sytem admin about device connection |
} |
echo json_encode(array('success' =>1, 'response' => 'Device connection establised')); |
} else { |
echo json_encode(array('status' =>0, 'response' => 'Device did not recognised')); |
} |
} |
function checkDeviceRegistered($imei) |
{ |
$res = $this->db->from('devices')->where(array('imei' => $imei))->get()->row(); // Checking/Fetching in DB |
if (!empty($res)) |
return false; |
else |
return true; |
} |
function registerDevice($imei) |
{ |
$this->db->insert('devices', array('imei' => $imei)); // Adding/Inserting new entery to DB |
} |