3v4l.org

run code in 300+ PHP versions simultaneously
<?php define("EBO_DEVICE_API_BASE", "http://device.api.eboradio.com"); define("EBO_DEVICE_METHOD_ACCESS", "/v1/authentication/access"); define("EBO_DEVICE_METHOD_ACTIVATION", "/v1/connection/activation"); define("EBO_DEVICE_METHOD_CONFIG", "/v1/server/config"); $serial_number = "EBOA1511CN82AEEF"; $device_key = "059d061d"; function http_request($url, $headers, $method='GET', $body=NULL) { global $error_msg; $curl=curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); if ($method == 'POST') { curl_setopt($curl, CURLOPT_POST, 1); if($body != NULL) curl_setopt($curl, CURLOPT_POSTFIELDS, $body); } curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($curl, CURLOPT_TIMEOUT, 10); $res = json_decode(curl_exec($curl), TRUE); $info = curl_getinfo($curl); curl_close($curl); print("\nhttp_response:\n".json_encode($res)."\n"); if($res == NULL || $res['message'] != "OK"){ print("\ncurl error:\n".json_encode($info)); if($res != NULL) { print("\nserver response:\n".json_encode($res)); $error_msg = $res['message']; } return NULL; } else { $error_msg = NULL; return $res['data']; } } function token_get() { global $serial_number, $device_key, $access_token, $expiration; $time_stamp = time(); $sha1_key=sha1($serial_number.$device_key.$time_stamp); $sign_key=md5($sha1_key); $headers = array("DEVICE-SN: ".$serial_number, "SIGNATURE: ".$sign_key, "REQUEST-TIME:".$time_stamp); print("\nHeaders :".json_encode($headers)."\n"); print("\nsignature:".$sign_key."\n"); $data = http_request(EBO_DEVICE_API_BASE.EBO_DEVICE_METHOD_ACCESS, $headers); if($data != NULL) { $access_token = $data['accesstoken']; $expiration = $time_stamp+240; print("\ntoken:".$access_token."\n"); } else { print("\nFailed to get token!\n"); $access_token = NULL; $expiration = 0; } return $access_token; } function activation() { global $access_token; $headers = array("ACCESS-TOKEN:".$access_token); return http_request(EBO_DEVICE_API_BASE.EBO_DEVICE_METHOD_ACTIVATION, $headers, 'POST'); } if(token_get() != NULL) { $headers = array("ACCESS-TOKEN:".$access_token); $config_data = http_request(EBO_DEVICE_API_BASE.EBO_DEVICE_METHOD_CONFIG, $headers); if($config_data != NULL) { print("\nconfig_data: ".strtolower($serial_number)."\n".json_encode($config_data)."\n"); } else { if ($error_msg == "DEVICE_NOT_ACTIVATED") { if(is_null(activation())) print("\ndevice activation fail !\n"); else { $config_data = http_request(EBO_DEVICE_API_BASE.EBO_DEVICE_METHOD_CONFIG, $headers); if($config_data != NULL) print("\nconfig_data: ".strtolower($serial_number)."\n".json_encode($config_data)."\n"); else print("\nget config fail !\n"); } } } } else print("\nget token fail ! \n"); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 79
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 47
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 78
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 55
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 55
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 77
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 78
Branch analysis from position: 78
Branch analysis from position: 77
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
Branch analysis from position: 78
Branch analysis from position: 79
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/he0dU
function name:  (null)
number of ops:  81
compiled vars:  !0 = $serial_number, !1 = $device_key, !2 = $headers, !3 = $access_token, !4 = $config_data, !5 = $error_msg
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   INIT_FCALL                                               'define'
          1        SEND_VAL                                                 'EBO_DEVICE_API_BASE'
          2        SEND_VAL                                                 'http%3A%2F%2Fdevice.api.eboradio.com'
          3        DO_ICALL                                                 
    3     4        INIT_FCALL                                               'define'
          5        SEND_VAL                                                 'EBO_DEVICE_METHOD_ACCESS'
          6        SEND_VAL                                                 '%2Fv1%2Fauthentication%2Faccess'
          7        DO_ICALL                                                 
    4     8        INIT_FCALL                                               'define'
          9        SEND_VAL                                                 'EBO_DEVICE_METHOD_ACTIVATION'
         10        SEND_VAL                                                 '%2Fv1%2Fconnection%2Factivation'
         11        DO_ICALL                                                 
    5    12        INIT_FCALL                                               'define'
         13        SEND_VAL                                                 'EBO_DEVICE_METHOD_CONFIG'
         14        SEND_VAL                                                 '%2Fv1%2Fserver%2Fconfig'
         15        DO_ICALL                                                 
    7    16        ASSIGN                                                   !0, 'EBOA1511CN82AEEF'
    8    17        ASSIGN                                                   !1, '059d061d'
   77    18        INIT_FCALL                                               'token_get'
         19        DO_FCALL                                      0  $12     
         20        IS_NOT_EQUAL                                             $12, null
         21      > JMPZ                                                     ~13, ->79
   78    22    >   CONCAT                                           ~14     'ACCESS-TOKEN%3A', !3
         23        INIT_ARRAY                                       ~15     ~14
         24        ASSIGN                                                   !2, ~15
   79    25        INIT_FCALL                                               'http_request'
         26        FETCH_CONSTANT                                   ~17     'EBO_DEVICE_API_BASE'
         27        FETCH_CONSTANT                                   ~18     'EBO_DEVICE_METHOD_CONFIG'
         28        CONCAT                                           ~19     ~17, ~18
         29        SEND_VAL                                                 ~19
         30        SEND_VAR                                                 !2
         31        DO_FCALL                                      0  $20     
         32        ASSIGN                                                   !4, $20
   81    33        IS_NOT_EQUAL                                             !4, null
         34      > JMPZ                                                     ~22, ->47
   82    35    >   INIT_FCALL                                               'strtolower'
         36        SEND_VAR                                                 !0
         37        DO_ICALL                                         $23     
         38        CONCAT                                           ~24     '%0Aconfig_data%3A+', $23
         39        CONCAT                                           ~25     ~24, '%0A'
         40        INIT_FCALL                                               'json_encode'
         41        SEND_VAR                                                 !4
         42        DO_ICALL                                         $26     
         43        CONCAT                                           ~27     ~25, $26
         44        CONCAT                                           ~28     ~27, '%0A'
         45        ECHO                                                     ~28
         46      > JMP                                                      ->78
   85    47    >   IS_EQUAL                                                 !5, 'DEVICE_NOT_ACTIVATED'
         48      > JMPZ                                                     ~29, ->78
   86    49    >   INIT_FCALL                                               'activation'
         50        DO_FCALL                                      0  $30     
         51        TYPE_CHECK                                    2          $30
         52      > JMPZ                                                     ~31, ->55
   87    53    >   ECHO                                                     '%0Adevice+activation+fail+%21%0A'
         54      > JMP                                                      ->78
   89    55    >   INIT_FCALL                                               'http_request'
         56        FETCH_CONSTANT                                   ~32     'EBO_DEVICE_API_BASE'
         57        FETCH_CONSTANT                                   ~33     'EBO_DEVICE_METHOD_CONFIG'
         58        CONCAT                                           ~34     ~32, ~33
         59        SEND_VAL                                                 ~34
         60        SEND_VAR                                                 !2
         61        DO_FCALL                                      0  $35     
         62        ASSIGN                                                   !4, $35
   90    63        IS_NOT_EQUAL                                             !4, null
         64      > JMPZ                                                     ~37, ->77
   91    65    >   INIT_FCALL                                               'strtolower'
         66        SEND_VAR                                                 !0
         67        DO_ICALL                                         $38     
         68        CONCAT                                           ~39     '%0Aconfig_data%3A+', $38
         69        CONCAT                                           ~40     ~39, '%0A'
         70        INIT_FCALL                                               'json_encode'
         71        SEND_VAR                                                 !4
         72        DO_ICALL                                         $41     
         73        CONCAT                                           ~42     ~40, $41
         74        CONCAT                                           ~43     ~42, '%0A'
         75        ECHO                                                     ~43
         76      > JMP                                                      ->78
   93    77    >   ECHO                                                     '%0Aget+config+fail+%21%0A'
         78    > > JMP                                                      ->80
   99    79    >   ECHO                                                     '%0Aget+token+fail+%21+%0A'
  100    80    > > RETURN                                                   1

Function http_request:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 42
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 42
Branch analysis from position: 36
2 jumps found. (Code = 47) Position 1 = 77, Position 2 = 80
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 81, Position 2 = 97
Branch analysis from position: 81
2 jumps found. (Code = 43) Position 1 = 88, Position 2 = 95
Branch analysis from position: 88
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 95
Branch analysis from position: 97
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
Branch analysis from position: 42
Branch analysis from position: 42
filename:       /in/he0dU
function name:  http_request
number of ops:  101
compiled vars:  !0 = $url, !1 = $headers, !2 = $method, !3 = $body, !4 = $error_msg, !5 = $curl, !6 = $res, !7 = $info
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      'GET'
          3        RECV_INIT                                        !3      null
   11     4        BIND_GLOBAL                                              !4, 'error_msg'
   13     5        INIT_FCALL_BY_NAME                                       'curl_init'
          6        DO_FCALL                                      0  $8      
          7        ASSIGN                                                   !5, $8
   14     8        INIT_FCALL_BY_NAME                                       'curl_setopt'
          9        SEND_VAR_EX                                              !5
         10        FETCH_CONSTANT                                   ~10     'CURLOPT_URL'
         11        SEND_VAL_EX                                              ~10
         12        SEND_VAR_EX                                              !0
         13        DO_FCALL                                      0          
   15    14        INIT_FCALL_BY_NAME                                       'curl_setopt'
         15        SEND_VAR_EX                                              !5
         16        FETCH_CONSTANT                                   ~12     'CURLOPT_HTTPHEADER'
         17        SEND_VAL_EX                                              ~12
         18        SEND_VAR_EX                                              !1
         19        DO_FCALL                                      0          
   16    20        INIT_FCALL_BY_NAME                                       'curl_setopt'
         21        SEND_VAR_EX                                              !5
         22        FETCH_CONSTANT                                   ~14     'CURLOPT_RETURNTRANSFER'
         23        SEND_VAL_EX                                              ~14
         24        SEND_VAL_EX                                              1
         25        DO_FCALL                                      0          
   17    26        IS_EQUAL                                                 !2, 'POST'
         27      > JMPZ                                                     ~16, ->42
   18    28    >   INIT_FCALL_BY_NAME                                       'curl_setopt'
         29        SEND_VAR_EX                                              !5
         30        FETCH_CONSTANT                                   ~17     'CURLOPT_POST'
         31        SEND_VAL_EX                                              ~17
         32        SEND_VAL_EX                                              1
         33        DO_FCALL                                      0          
   19    34        IS_NOT_EQUAL                                             !3, null
         35      > JMPZ                                                     ~19, ->42
   20    36    >   INIT_FCALL_BY_NAME                                       'curl_setopt'
         37        SEND_VAR_EX                                              !5
         38        FETCH_CONSTANT                                   ~20     'CURLOPT_POSTFIELDS'
         39        SEND_VAL_EX                                              ~20
         40        SEND_VAR_EX                                              !3
         41        DO_FCALL                                      0          
   23    42    >   INIT_FCALL_BY_NAME                                       'curl_setopt'
         43        SEND_VAR_EX                                              !5
         44        FETCH_CONSTANT                                   ~22     'CURLOPT_CONNECTTIMEOUT'
         45        SEND_VAL_EX                                              ~22
         46        SEND_VAL_EX                                              5
         47        DO_FCALL                                      0          
   24    48        INIT_FCALL_BY_NAME                                       'curl_setopt'
         49        SEND_VAR_EX                                              !5
         50        FETCH_CONSTANT                                   ~24     'CURLOPT_TIMEOUT'
         51        SEND_VAL_EX                                              ~24
         52        SEND_VAL_EX                                              10
         53        DO_FCALL                                      0          
   26    54        INIT_FCALL                                               'json_decode'
         55        INIT_FCALL_BY_NAME                                       'curl_exec'
         56        SEND_VAR_EX                                              !5
         57        DO_FCALL                                      0  $26     
         58        SEND_VAR                                                 $26
         59        SEND_VAL                                                 <true>
         60        DO_ICALL                                         $27     
         61        ASSIGN                                                   !6, $27
   27    62        INIT_FCALL_BY_NAME                                       'curl_getinfo'
         63        SEND_VAR_EX                                              !5
         64        DO_FCALL                                      0  $29     
         65        ASSIGN                                                   !7, $29
   28    66        INIT_FCALL_BY_NAME                                       'curl_close'
         67        SEND_VAR_EX                                              !5
         68        DO_FCALL                                      0          
   29    69        INIT_FCALL                                               'json_encode'
         70        SEND_VAR                                                 !6
         71        DO_ICALL                                         $32     
         72        CONCAT                                           ~33     '%0Ahttp_response%3A%0A', $32
         73        CONCAT                                           ~34     ~33, '%0A'
         74        ECHO                                                     ~34
   30    75        IS_EQUAL                                         ~35     !6, null
         76      > JMPNZ_EX                                         ~35     ~35, ->80
         77    >   FETCH_DIM_R                                      ~36     !6, 'message'
         78        IS_NOT_EQUAL                                     ~37     ~36, 'OK'
         79        BOOL                                             ~35     ~37
         80    > > JMPZ                                                     ~35, ->97
   31    81    >   INIT_FCALL                                               'json_encode'
         82        SEND_VAR                                                 !7
         83        DO_ICALL                                         $38     
         84        CONCAT                                           ~39     '%0Acurl+error%3A%0A', $38
         85        ECHO                                                     ~39
   32    86        IS_NOT_EQUAL                                             !6, null
         87      > JMPZ                                                     ~40, ->95
   33    88    >   INIT_FCALL                                               'json_encode'
         89        SEND_VAR                                                 !6
         90        DO_ICALL                                         $41     
         91        CONCAT                                           ~42     '%0Aserver+response%3A%0A', $41
         92        ECHO                                                     ~42
   34    93        FETCH_DIM_R                                      ~43     !6, 'message'
         94        ASSIGN                                                   !4, ~43
   36    95    > > RETURN                                                   null
         96*       JMP                                                      ->100
   39    97    >   ASSIGN                                                   !4, null
   40    98        FETCH_DIM_R                                      ~46     !6, 'data'
         99      > RETURN                                                   ~46
   42   100*     > RETURN                                                   null

End of function http_request

Function token_get:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 51
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 51
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/he0dU
function name:  token_get
number of ops:  56
compiled vars:  !0 = $serial_number, !1 = $device_key, !2 = $access_token, !3 = $expiration, !4 = $time_stamp, !5 = $sha1_key, !6 = $sign_key, !7 = $headers, !8 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   45     0  E >   BIND_GLOBAL                                              !0, 'serial_number'
          1        BIND_GLOBAL                                              !1, 'device_key'
          2        BIND_GLOBAL                                              !2, 'access_token'
          3        BIND_GLOBAL                                              !3, 'expiration'
   47     4        INIT_FCALL                                               'time'
          5        DO_ICALL                                         $9      
          6        ASSIGN                                                   !4, $9
   48     7        INIT_FCALL                                               'sha1'
          8        CONCAT                                           ~11     !0, !1
          9        CONCAT                                           ~12     ~11, !4
         10        SEND_VAL                                                 ~12
         11        DO_ICALL                                         $13     
         12        ASSIGN                                                   !5, $13
   49    13        INIT_FCALL                                               'md5'
         14        SEND_VAR                                                 !5
         15        DO_ICALL                                         $15     
         16        ASSIGN                                                   !6, $15
   50    17        CONCAT                                           ~17     'DEVICE-SN%3A+', !0
         18        INIT_ARRAY                                       ~18     ~17
   51    19        CONCAT                                           ~19     'SIGNATURE%3A+', !6
         20        ADD_ARRAY_ELEMENT                                ~18     ~19
   52    21        CONCAT                                           ~20     'REQUEST-TIME%3A', !4
         22        ADD_ARRAY_ELEMENT                                ~18     ~20
   50    23        ASSIGN                                                   !7, ~18
   54    24        INIT_FCALL                                               'json_encode'
         25        SEND_VAR                                                 !7
         26        DO_ICALL                                         $22     
         27        CONCAT                                           ~23     '%0AHeaders+%3A', $22
         28        CONCAT                                           ~24     ~23, '%0A'
         29        ECHO                                                     ~24
   55    30        CONCAT                                           ~25     '%0Asignature%3A', !6
         31        CONCAT                                           ~26     ~25, '%0A'
         32        ECHO                                                     ~26
   57    33        INIT_FCALL                                               'http_request'
         34        FETCH_CONSTANT                                   ~27     'EBO_DEVICE_API_BASE'
         35        FETCH_CONSTANT                                   ~28     'EBO_DEVICE_METHOD_ACCESS'
         36        CONCAT                                           ~29     ~27, ~28
         37        SEND_VAL                                                 ~29
         38        SEND_VAR                                                 !7
         39        DO_FCALL                                      0  $30     
         40        ASSIGN                                                   !8, $30
   58    41        IS_NOT_EQUAL                                             !8, null
         42      > JMPZ                                                     ~32, ->51
   59    43    >   FETCH_DIM_R                                      ~33     !8, 'accesstoken'
         44        ASSIGN                                                   !2, ~33
   60    45        ADD                                              ~35     !4, 240
         46        ASSIGN                                                   !3, ~35
   61    47        CONCAT                                           ~37     '%0Atoken%3A', !2
         48        CONCAT                                           ~38     ~37, '%0A'
         49        ECHO                                                     ~38
         50      > JMP                                                      ->54
   64    51    >   ECHO                                                     '%0AFailed+to+get+token%21%0A'
   65    52        ASSIGN                                                   !2, null
   66    53        ASSIGN                                                   !3, 0
   68    54    > > RETURN                                                   !2
   69    55*     > RETURN                                                   null

End of function token_get

Function activation:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/he0dU
function name:  activation
number of ops:  14
compiled vars:  !0 = $access_token, !1 = $headers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   72     0  E >   BIND_GLOBAL                                              !0, 'access_token'
   73     1        CONCAT                                           ~2      'ACCESS-TOKEN%3A', !0
          2        INIT_ARRAY                                       ~3      ~2
          3        ASSIGN                                                   !1, ~3
   74     4        INIT_FCALL                                               'http_request'
          5        FETCH_CONSTANT                                   ~5      'EBO_DEVICE_API_BASE'
          6        FETCH_CONSTANT                                   ~6      'EBO_DEVICE_METHOD_ACTIVATION'
          7        CONCAT                                           ~7      ~5, ~6
          8        SEND_VAL                                                 ~7
          9        SEND_VAR                                                 !1
         10        SEND_VAL                                                 'POST'
         11        DO_FCALL                                      0  $8      
         12      > RETURN                                                   $8
   75    13*     > RETURN                                                   null

End of function activation

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.53 ms | 1422 KiB | 33 Q