get_query_action.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. // 設置資料類型 json,編碼格式 utf-8
  3. header('Content-Type: application/json; charset=UTF-8');
  4. // 判斷如果是 GET 請求,則進行搜尋;如果是 POST 請求,則進行新建
  5. // $_SERVER['REQUEST_METHOD'] 返回訪問頁面使用的請求方法
  6. if ($_SERVER['REQUEST_METHOD'] == "GET") {
  7. create();
  8. } else if ($_SERVER['REQUEST_METHOD'] == "POST") {
  9. create();
  10. }
  11. // 新建員工
  12. function create() {
  13. if($_REQUEST['opt']!=0 && $_REQUEST['opt']!=1 && $_REQUEST['opt']!=2 && $_REQUEST['opt']!=3 && $_REQUEST['opt']!=4){
  14. echo "parameter error, opt should be integer between 0~4";
  15. exit;
  16. }
  17. chdir("/root");
  18. exec("'./WebService' 'query'",$output,$return_var);
  19. if(count($output)==0){
  20. // echo '<script>alert("Something went wrong on machine");</script>';
  21. echo "Something went wrong on machine";
  22. exit;
  23. }
  24. if(trim($output[0])=="InitShareMemory Error"){
  25. // echo '<script>alert("InitShareMemory Error");</script>';
  26. echo "InitShareMemory Error";
  27. exit;
  28. }
  29. $obj[1] = trim($output[0]);
  30. $obj[2] = trim($output[1]);
  31. $obj[3] = trim($output[2]);
  32. $obj[4] = trim($output[3]);
  33. $obj10 = json_decode(trim($output[0]));
  34. $obj20 = json_decode(trim($output[1]));
  35. $obj30 = json_decode(trim($output[2]));
  36. $obj40 = json_decode(trim($output[3]));
  37. $arr=array($obj10,$obj20,$obj30,$obj40);
  38. $obj[0]=json_encode($arr);
  39. echo $obj[$_REQUEST['opt']];
  40. }
  41. ?>