3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Priatek Vending PHP Server-Side * Checks POST requests. It checks a 'tag' in a post response, and looks * for other tag-specific data. Tag if one of the following, along with the * other required data: * * Tag Other Tag 1 Other Tag 2 * ========================================== * login | ID OR user_name | password * logout | ID OR user_name | * getTickets | user_name | * addTickets | user_name | tickets * subTickets | user_name | tickets * * Other Tag Descriptions * ========================================== * user_name : ther user's name on the databae in the user_name column * ID : the user's ID in the ID column * password : the contents of the pass_hash column * ticket : an integer of the number of tickets to add or remove * * Brief Explinations * ========================================== * login - User to lookup and mark a user a logged in * logout - Logout a user setting a boolean "loggedin" in the databse. * getTickets - Return a user's tickets * addTickets - Add to a user's tickets * subTickets - Subtract from a user's tickets * viewLogs - Return the first ten entires in the adminlogs and redemptionstable */ //Echos an error message, given a tag, back to the user function sendError($tag, $message) { $response = array("tag" => $tag, "error" => TRUE); $response['error_msg'] = $message; echo json_encode($response); } if (isset($_POST['tag']) && $_POST['tag'] != '') { require_once 'include/DB_Functions.php'; $db = new DB_Functions(); //object of the class containing all the functions //response Array. Will be json_encode'd sent back $tag = $_POST['tag']; $response = array("tag" => $tag, "error" => FALSE); /********response when tag == login*************/ if ($tag == 'login') { // Request type is check Login $id = $_POST['ID']; $username = $_POST['user_name']; $password = $_POST['password']; $machinesID = $_POST["machinesID"]; $itemsID = $_POST["itemsID"]; // Lookup by either username, or ID $user = $db->loginUserByPassword($id, $username, $password, $machinesID); if ($user != false) { //Record was found $response["user"]["tickets"] = $user["tickets"]; $response["error"] = FALSE; $response["user"]["name"] = $user["name"]; $response["user"]["id"] = $user["ID"]; $response["user"]["created_at"] = $user["created_at"]; $response["user"]["updated_at"] = $user["updated_at"]; echo json_encode($response); } else { //record was not found sendError($tag, "Incorrect id or password!"); } } /********response when tag == ViewLogs*************/ else if ($tag == 'viewLogs') { $id = $_POST["id"]; $logs = $db->getMachineLogs($id); if($logs != FALSE) { $response["logs"] = $logs; echo json_encode($response); } else { sendError($tag, "Error retrieving logs"); } } /********response when tag == addTickets*************/ else if ($tag == 'addTickets') { //TODO: add a restrain, if the user doesnt exist tickets cannot be adde $user_name = $_POST["user_name"]; $tickets = $_POST["tickets"]; $currentBalance = $db->getTickets($user_name); $newBalance = $currentBalance["tickets"] + $tickets; if($db->addTickets($user_name, $tickets)){ $response["newBalance"]= $newBalance; echo json_encode($response); } else { sendError($tag, "processing error"); } } /********response when tag == subTickets*************/ else if ($tag == 'subTickets'){ //TODO: add a restrain, if the user doesnt exist tickets cannot be subtracted $user_name = $_POST["user_name"]; $tickets = $_POST["tickets"]; $machinesID = $_POST["machinesID"]; $itemsID = $_POST["itemsID"]; $currentBalance = $db->getTickets($user_name, $machinesID, $itemsID); $newBalance = $currentBalance["tickets"] - $tickets; if($newBalance > 0) { if($db->subTickets($user_name, $tickets)) { $response["newBalance"]= $newBalance; echo json_encode($response); } else { sendError($tag, "processing error"); } } else { sendError($tag, "Subtracting tickets will result in a negative value!"); } } /******** response when tag == getTickets *************/ else if ($tag == 'getTickets') { $user_name = $_POST["user_name"]; $balance = $db->getTickets($user_name); if($balance != FALSE) { $response["tickets"] = $balance["tickets"]; echo json_encode($response); } else { sendError($tag, "error processing the tickets"); } } /********response when tag == unknown*************/ else { sendError($tag, "Unknown tag given"); } /********response when tag == empty*************/ } else { sendError($tag, "Empty tag value given"); } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 207
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 76
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 44, Position 2 = 71
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
1 jumps found. (Code = 42) Position 1 = 206
Branch analysis from position: 206
1 jumps found. (Code = 42) Position 1 = 211
Branch analysis from position: 211
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
1 jumps found. (Code = 42) Position 1 = 206
Branch analysis from position: 206
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 78, Position 2 = 99
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 94
Branch analysis from position: 87
1 jumps found. (Code = 42) Position 1 = 98
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 206
Branch analysis from position: 206
Branch analysis from position: 94
1 jumps found. (Code = 42) Position 1 = 206
Branch analysis from position: 206
Branch analysis from position: 99
2 jumps found. (Code = 43) Position 1 = 101, Position 2 = 131
Branch analysis from position: 101
2 jumps found. (Code = 43) Position 1 = 119, Position 2 = 126
Branch analysis from position: 119
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
1 jumps found. (Code = 42) Position 1 = 206
Branch analysis from position: 206
Branch analysis from position: 126
1 jumps found. (Code = 42) Position 1 = 206
Branch analysis from position: 206
Branch analysis from position: 131
2 jumps found. (Code = 43) Position 1 = 133, Position 2 = 178
Branch analysis from position: 133
2 jumps found. (Code = 43) Position 1 = 156, Position 2 = 173
Branch analysis from position: 156
2 jumps found. (Code = 43) Position 1 = 161, Position 2 = 168
Branch analysis from position: 161
1 jumps found. (Code = 42) Position 1 = 172
Branch analysis from position: 172
1 jumps found. (Code = 42) Position 1 = 177
Branch analysis from position: 177
1 jumps found. (Code = 42) Position 1 = 206
Branch analysis from position: 206
Branch analysis from position: 168
1 jumps found. (Code = 42) Position 1 = 177
Branch analysis from position: 177
Branch analysis from position: 173
1 jumps found. (Code = 42) Position 1 = 206
Branch analysis from position: 206
Branch analysis from position: 178
2 jumps found. (Code = 43) Position 1 = 180, Position 2 = 202
Branch analysis from position: 180
2 jumps found. (Code = 43) Position 1 = 189, Position 2 = 197
Branch analysis from position: 189
1 jumps found. (Code = 42) Position 1 = 201
Branch analysis from position: 201
1 jumps found. (Code = 42) Position 1 = 206
Branch analysis from position: 206
Branch analysis from position: 197
1 jumps found. (Code = 42) Position 1 = 206
Branch analysis from position: 206
Branch analysis from position: 202
1 jumps found. (Code = 42) Position 1 = 211
Branch analysis from position: 211
Branch analysis from position: 207
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/3aF6L
function name:  (null)
number of ops:  212
compiled vars:  !0 = $db, !1 = $tag, !2 = $response, !3 = $id, !4 = $username, !5 = $password, !6 = $machinesID, !7 = $itemsID, !8 = $user, !9 = $logs, !10 = $user_name, !11 = $tickets, !12 = $currentBalance, !13 = $newBalance, !14 = $balance
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   FETCH_IS                                         ~15     '_POST'
          1        ISSET_ISEMPTY_DIM_OBJ                         0  ~16     ~15, 'tag'
          2      > JMPZ_EX                                          ~16     ~16, ->7
          3    >   FETCH_R                      global              ~17     '_POST'
          4        FETCH_DIM_R                                      ~18     ~17, 'tag'
          5        IS_NOT_EQUAL                                     ~19     ~18, ''
          6        BOOL                                             ~16     ~19
          7    > > JMPZ                                                     ~16, ->207
   40     8    >   INCLUDE_OR_EVAL                                          'include%2FDB_Functions.php', REQUIRE_ONCE
   41     9        NEW                                              $21     'DB_Functions'
         10        DO_FCALL                                      0          
         11        ASSIGN                                                   !0, $21
   44    12        FETCH_R                      global              ~24     '_POST'
         13        FETCH_DIM_R                                      ~25     ~24, 'tag'
         14        ASSIGN                                                   !1, ~25
   45    15        INIT_ARRAY                                       ~27     !1, 'tag'
         16        ADD_ARRAY_ELEMENT                                ~27     <false>, 'error'
         17        ASSIGN                                                   !2, ~27
   48    18        IS_EQUAL                                                 !1, 'login'
         19      > JMPZ                                                     ~29, ->76
   50    20    >   FETCH_R                      global              ~30     '_POST'
         21        FETCH_DIM_R                                      ~31     ~30, 'ID'
         22        ASSIGN                                                   !3, ~31
   51    23        FETCH_R                      global              ~33     '_POST'
         24        FETCH_DIM_R                                      ~34     ~33, 'user_name'
         25        ASSIGN                                                   !4, ~34
   52    26        FETCH_R                      global              ~36     '_POST'
         27        FETCH_DIM_R                                      ~37     ~36, 'password'
         28        ASSIGN                                                   !5, ~37
   53    29        FETCH_R                      global              ~39     '_POST'
         30        FETCH_DIM_R                                      ~40     ~39, 'machinesID'
         31        ASSIGN                                                   !6, ~40
   54    32        FETCH_R                      global              ~42     '_POST'
         33        FETCH_DIM_R                                      ~43     ~42, 'itemsID'
         34        ASSIGN                                                   !7, ~43
   56    35        INIT_METHOD_CALL                                         !0, 'loginUserByPassword'
         36        SEND_VAR_EX                                              !3
         37        SEND_VAR_EX                                              !4
         38        SEND_VAR_EX                                              !5
         39        SEND_VAR_EX                                              !6
         40        DO_FCALL                                      0  $45     
         41        ASSIGN                                                   !8, $45
   57    42        BOOL                                             ~47     !8
         43      > JMPZ                                                     ~47, ->71
   59    44    >   FETCH_DIM_R                                      ~50     !8, 'tickets'
         45        FETCH_DIM_W                                      $48     !2, 'user'
         46        ASSIGN_DIM                                               $48, 'tickets'
         47        OP_DATA                                                  ~50
   60    48        ASSIGN_DIM                                               !2, 'error'
         49        OP_DATA                                                  <false>
   61    50        FETCH_DIM_R                                      ~54     !8, 'name'
         51        FETCH_DIM_W                                      $52     !2, 'user'
         52        ASSIGN_DIM                                               $52, 'name'
         53        OP_DATA                                                  ~54
   62    54        FETCH_DIM_R                                      ~57     !8, 'ID'
         55        FETCH_DIM_W                                      $55     !2, 'user'
         56        ASSIGN_DIM                                               $55, 'id'
         57        OP_DATA                                                  ~57
   63    58        FETCH_DIM_R                                      ~60     !8, 'created_at'
         59        FETCH_DIM_W                                      $58     !2, 'user'
         60        ASSIGN_DIM                                               $58, 'created_at'
         61        OP_DATA                                                  ~60
   64    62        FETCH_DIM_R                                      ~63     !8, 'updated_at'
         63        FETCH_DIM_W                                      $61     !2, 'user'
         64        ASSIGN_DIM                                               $61, 'updated_at'
         65        OP_DATA                                                  ~63
   65    66        INIT_FCALL                                               'json_encode'
         67        SEND_VAR                                                 !2
         68        DO_ICALL                                         $64     
         69        ECHO                                                     $64
         70      > JMP                                                      ->75
   68    71    >   INIT_FCALL                                               'senderror'
         72        SEND_VAR                                                 !1
         73        SEND_VAL                                                 'Incorrect+id+or+password%21'
         74        DO_FCALL                                      0          
         75    > > JMP                                                      ->206
   73    76    >   IS_EQUAL                                                 !1, 'viewLogs'
         77      > JMPZ                                                     ~66, ->99
   74    78    >   FETCH_R                      global              ~67     '_POST'
         79        FETCH_DIM_R                                      ~68     ~67, 'id'
         80        ASSIGN                                                   !3, ~68
   75    81        INIT_METHOD_CALL                                         !0, 'getMachineLogs'
         82        SEND_VAR_EX                                              !3
         83        DO_FCALL                                      0  $70     
         84        ASSIGN                                                   !9, $70
   76    85        BOOL                                             ~72     !9
         86      > JMPZ                                                     ~72, ->94
   77    87    >   ASSIGN_DIM                                               !2, 'logs'
         88        OP_DATA                                                  !9
   78    89        INIT_FCALL                                               'json_encode'
         90        SEND_VAR                                                 !2
         91        DO_ICALL                                         $74     
         92        ECHO                                                     $74
         93      > JMP                                                      ->98
   80    94    >   INIT_FCALL                                               'senderror'
         95        SEND_VAR                                                 !1
         96        SEND_VAL                                                 'Error+retrieving+logs'
         97        DO_FCALL                                      0          
         98    > > JMP                                                      ->206
   85    99    >   IS_EQUAL                                                 !1, 'addTickets'
        100      > JMPZ                                                     ~76, ->131
   87   101    >   FETCH_R                      global              ~77     '_POST'
        102        FETCH_DIM_R                                      ~78     ~77, 'user_name'
        103        ASSIGN                                                   !10, ~78
   88   104        FETCH_R                      global              ~80     '_POST'
        105        FETCH_DIM_R                                      ~81     ~80, 'tickets'
        106        ASSIGN                                                   !11, ~81
   89   107        INIT_METHOD_CALL                                         !0, 'getTickets'
        108        SEND_VAR_EX                                              !10
        109        DO_FCALL                                      0  $83     
        110        ASSIGN                                                   !12, $83
   90   111        FETCH_DIM_R                                      ~85     !12, 'tickets'
        112        ADD                                              ~86     ~85, !11
        113        ASSIGN                                                   !13, ~86
   92   114        INIT_METHOD_CALL                                         !0, 'addTickets'
        115        SEND_VAR_EX                                              !10
        116        SEND_VAR_EX                                              !11
        117        DO_FCALL                                      0  $88     
        118      > JMPZ                                                     $88, ->126
   93   119    >   ASSIGN_DIM                                               !2, 'newBalance'
        120        OP_DATA                                                  !13
   94   121        INIT_FCALL                                               'json_encode'
        122        SEND_VAR                                                 !2
        123        DO_ICALL                                         $90     
        124        ECHO                                                     $90
        125      > JMP                                                      ->130
   96   126    >   INIT_FCALL                                               'senderror'
        127        SEND_VAR                                                 !1
        128        SEND_VAL                                                 'processing+error'
        129        DO_FCALL                                      0          
        130    > > JMP                                                      ->206
  101   131    >   IS_EQUAL                                                 !1, 'subTickets'
        132      > JMPZ                                                     ~92, ->178
  103   133    >   FETCH_R                      global              ~93     '_POST'
        134        FETCH_DIM_R                                      ~94     ~93, 'user_name'
        135        ASSIGN                                                   !10, ~94
  104   136        FETCH_R                      global              ~96     '_POST'
        137        FETCH_DIM_R                                      ~97     ~96, 'tickets'
        138        ASSIGN                                                   !11, ~97
  105   139        FETCH_R                      global              ~99     '_POST'
        140        FETCH_DIM_R                                      ~100    ~99, 'machinesID'
        141        ASSIGN                                                   !6, ~100
  106   142        FETCH_R                      global              ~102    '_POST'
        143        FETCH_DIM_R                                      ~103    ~102, 'itemsID'
        144        ASSIGN                                                   !7, ~103
  107   145        INIT_METHOD_CALL                                         !0, 'getTickets'
        146        SEND_VAR_EX                                              !10
        147        SEND_VAR_EX                                              !6
        148        SEND_VAR_EX                                              !7
        149        DO_FCALL                                      0  $105    
        150        ASSIGN                                                   !12, $105
  108   151        FETCH_DIM_R                                      ~107    !12, 'tickets'
        152        SUB                                              ~108    ~107, !11
        153        ASSIGN                                                   !13, ~108
  110   154        IS_SMALLER                                               0, !13
        155      > JMPZ                                                     ~110, ->173
  111   156    >   INIT_METHOD_CALL                                         !0, 'subTickets'
        157        SEND_VAR_EX                                              !10
        158        SEND_VAR_EX                                              !11
        159        DO_FCALL                                      0  $111    
        160      > JMPZ                                                     $111, ->168
  112   161    >   ASSIGN_DIM                                               !2, 'newBalance'
        162        OP_DATA                                                  !13
  113   163        INIT_FCALL                                               'json_encode'
        164        SEND_VAR                                                 !2
        165        DO_ICALL                                         $113    
        166        ECHO                                                     $113
        167      > JMP                                                      ->172
  115   168    >   INIT_FCALL                                               'senderror'
        169        SEND_VAR                                                 !1
        170        SEND_VAL                                                 'processing+error'
        171        DO_FCALL                                      0          
        172    > > JMP                                                      ->177
  118   173    >   INIT_FCALL                                               'senderror'
        174        SEND_VAR                                                 !1
        175        SEND_VAL                                                 'Subtracting+tickets+will+result+in+a+negative+value%21'
        176        DO_FCALL                                      0          
        177    > > JMP                                                      ->206
  123   178    >   IS_EQUAL                                                 !1, 'getTickets'
        179      > JMPZ                                                     ~116, ->202
  124   180    >   FETCH_R                      global              ~117    '_POST'
        181        FETCH_DIM_R                                      ~118    ~117, 'user_name'
        182        ASSIGN                                                   !10, ~118
  125   183        INIT_METHOD_CALL                                         !0, 'getTickets'
        184        SEND_VAR_EX                                              !10
        185        DO_FCALL                                      0  $120    
        186        ASSIGN                                                   !14, $120
  126   187        BOOL                                             ~122    !14
        188      > JMPZ                                                     ~122, ->197
  127   189    >   FETCH_DIM_R                                      ~124    !14, 'tickets'
        190        ASSIGN_DIM                                               !2, 'tickets'
        191        OP_DATA                                                  ~124
  128   192        INIT_FCALL                                               'json_encode'
        193        SEND_VAR                                                 !2
        194        DO_ICALL                                         $125    
        195        ECHO                                                     $125
        196      > JMP                                                      ->201
  130   197    >   INIT_FCALL                                               'senderror'
        198        SEND_VAR                                                 !1
        199        SEND_VAL                                                 'error+processing+the+tickets'
        200        DO_FCALL                                      0          
        201    > > JMP                                                      ->206
  136   202    >   INIT_FCALL                                               'senderror'
        203        SEND_VAR                                                 !1
        204        SEND_VAL                                                 'Unknown+tag+given'
        205        DO_FCALL                                      0          
        206    > > JMP                                                      ->211
  141   207    >   INIT_FCALL                                               'senderror'
        208        SEND_VAR                                                 !1
        209        SEND_VAL                                                 'Empty+tag+value+given'
        210        DO_FCALL                                      0          
  145   211    > > RETURN                                                   1

Function senderror:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/3aF6L
function name:  sendError
number of ops:  12
compiled vars:  !0 = $tag, !1 = $message, !2 = $response
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   34     2        INIT_ARRAY                                       ~3      !0, 'tag'
          3        ADD_ARRAY_ELEMENT                                ~3      <true>, 'error'
          4        ASSIGN                                                   !2, ~3
   35     5        ASSIGN_DIM                                               !2, 'error_msg'
          6        OP_DATA                                                  !1
   36     7        INIT_FCALL                                               'json_encode'
          8        SEND_VAR                                                 !2
          9        DO_ICALL                                         $6      
         10        ECHO                                                     $6
   37    11      > RETURN                                                   null

End of function senderror

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.26 ms | 1419 KiB | 23 Q