Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*****************************************
- * API Version : 0.1
- * API Service : Operational Back Office Server
- ******************************************/
- //load database config and other data libs
- require_once ("../../app/config/config.php");
- require_once ("../../app/general/Security.php");
- require ("../../app/securimage/Securimage.php");
- //require_once ("../../app/config/FUnction_connect.php");
- //API CALL DATA EXAMPLE & TEST
- /************************************
- ** Developer can modified these code if it neccessary, otherwise you can ignore it.
- ** User data from DB being parsed to json data!
- ** password decryptor https://md5hashing.net/hash
- /************************************/
- $act = isset($_REQUEST['act']) ? $_REQUEST['act'] : '';
- switch ($act) {
- /*case 'registration':
- //registration
- # code...
- $idobu = ($_REQUEST['nomorobu']);
- $vehicenum = strtolower($_REQUEST['nomorobu']);
- $username = strtolower($_REQUEST['nomorkendaraan']);
- $email = strtolower($_REQUEST['email']);
- $password = $_REQUEST['password'];
- $handphone = $_REQUEST['mobnumb'];
- break;*/
- /* case 'login':
- //login validation is to check user accounts validation
- # code...
- $id = empty($_REQUEST['id']);
- $user = $_REQUEST['username'];
- $pass = ($_REQUEST['password']);
- $password = hash('sha512', $pass);
- //query = ("SELECT * from m_user");
- $stmt = $mysqli->prepare("SELECT id, username, password, salt
- FROM m_user
- WHERE (email = ? OR username = ?) AND active = 1
- LIMIT 1");
- $stmt->bind_param('ss', $email, $user);
- $stmt->execute(); // Execute the prepared query.
- $stmt->store_result();
- // get variables from result.
- $stmt->bind_result($user_id, $username, $db_password, $salt);
- $stmt->fetch();
- // hash the password with the unique salt.
- $password = hash('sha512', $password . $salt);
- //query
- $query = ("SELECT * FROM m_user WHERE username='$user' AND password='$password' ");
- $result = $mysqli->query($query);
- $data = array();
- while ($row = mysqli_fetch_assoc($result)){
- $data[]= array(
- "id" => $row['id'],
- "username" => $row['username'],
- "password" => $row['password'],
- );
- }
- if(!empty($data)){
- //respon data
- $json = array(
- 'status' => 'success, 200',
- 'data' => $data
- );
- }else{
- $json = array(
- 'status' => 'error, 400',
- 'msg' => 'wrong username or password ',
- );
- }
- echo json_encode($json);
- break;*/
- case 'validation':
- # this code to check registered obu and validate obu id on server
- $id = $_REQUEST = ['id'];
- $obuid = $_REQUEST = ['obu_id'];
- $noplat = $_REQUEST = ['no_plat'];
- $timestamp = date('Y-m-d H:i:s');
- //$query = ("SELECT * FROM obu_registered(id,obu_id,no_plat, date) VALUES ('$id', '$obu_id', '$no_plat', 'NOW()'");
- $query = ("SELECT * FROM 'obu_registered' WHERE obu_id ='$obuid' AND no_plat ='$noplat' AND timestamp = '$timestamp'");
- $result = $mysqli->query($query);
- //$data = array();
- while ($row = mysqli_fetch_assoc($result)){
- $data[]= array(
- "id" => $row['id'],
- "obuid" => $row['obu_id'],
- "noplat" => $row['no_plat'],
- "time" => $row['Y-m-d H:i:s'],
- );
- }
- $json = array(
- 'status' => 'OK, 200',
- 'msg' => 'Registered OBU & plat number',
- );
- echo json_encode($json);
- /*
- //checking
- if(($obuid === $row['obu_id']) && ($noplat === $row['no_plat']) === true)
- {
- $json = array(
- 'status' => 'OK, 200',
- 'msg' => 'Registered OBU & plat number',
- );
- }
- elseif(($obuid === $row['obu_id']) && ($noplat !== $row['noplat']) === false)
- {
- $json = array(
- 'status' => 'NOK, 400',
- 'msg' => 'unregistered plat number',
- );
- }
- elseif(($obuid !== $row['obu_id']) && ($noplat === $row['noplat']) === false)
- {
- $json = array(
- 'status' => 'NOK, 400',
- 'msg' => 'unregistered OBU',
- );
- }
- else(($obuid !== $row['obu_id']) && ($noplat !== $row['noplat']) === false);
- {
- $json = array(
- 'status' => 'NOK, 400',
- 'msg' => 'unregistered OBU & plat number',
- );
- }
- */
- break;
- default:
- # code...
- echo "akhir";
- break;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement