3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * TME API - code snippet. * * More info at: https://developers.tme.eu */ $token = 'b050bd709a43eecc443820c022b6774ca703ddb216b6f6765f';//'<put_your_token_here>'; $app_secret = '5656847466f0e5d08577';//<put_your_app_secret_here>'; $params = array( 'SymbolList' => array('1N4007'), 'Country' => 'PL', 'Currency' => 'PLN', 'Language' => 'PL', ); $response = api_call('Products/GetPrices', $params, $token, $app_secret, true); $result = json_decode($response, true); var_dump(PHP_VERSION); echo '<pre>'; print_r($result); echo '</pre>'; $w = stream_get_wrappers(); echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "\n"; echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n"; echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n"; echo 'wrappers: ', var_dump($w); //--------------------------------------------------------- function api_call($action, $params, $token, $app_secret, $show_header=false) { $api_url = 'https://api.tme.eu/' . $action . '.json'; $curl = curl_init(); // calculate HMAC-SHA1 signature $params['Token'] = $token; ksort($params); // In PHP 5.4 http_build_query() offers enc_type parameter (PHP_QUERY_RFC3986) which replaces bellow snippet. $encoded_params = str_replace( array('+', '%7E'), array('%20', '~'), http_build_query($params) ); $signature_base = 'POST' . '&' . rawurlencode($api_url) . '&' . rawurlencode($encoded_params); $api_signature = base64_encode(hash_hmac('sha1', $signature_base, $app_secret, true)); $params['ApiSignature'] = $api_signature; //-- curl_setopt($curl, CURLOPT_URL, $api_url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_VERBOSE, 1); curl_setopt($curl, CURLOPT_HEADER, 1); $response = curl_exec($curl); $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); if($show_header){ print_r($header); } curl_close($curl); return $body; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 45
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
Branch analysis from position: 56
Branch analysis from position: 34
2 jumps found. (Code = 43) Position 1 = 43, Position 2 = 45
Branch analysis from position: 43
Branch analysis from position: 45
filename:       /in/6CZEC
function name:  (null)
number of ops:  65
compiled vars:  !0 = $token, !1 = $app_secret, !2 = $params, !3 = $response, !4 = $result, !5 = $w
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   ASSIGN                                                   !0, 'b050bd709a43eecc443820c022b6774ca703ddb216b6f6765f'
    9     1        ASSIGN                                                   !1, '5656847466f0e5d08577'
   10     2        ASSIGN                                                   !2, <array>
   17     3        INIT_FCALL_BY_NAME                                       'api_call'
          4        SEND_VAL_EX                                              'Products%2FGetPrices'
          5        SEND_VAR_EX                                              !2
          6        SEND_VAR_EX                                              !0
          7        SEND_VAR_EX                                              !1
          8        SEND_VAL_EX                                              <true>
          9        DO_FCALL                                      0  $9      
         10        ASSIGN                                                   !3, $9
   18    11        INIT_FCALL                                               'json_decode'
         12        SEND_VAR                                                 !3
         13        SEND_VAL                                                 <true>
         14        DO_ICALL                                         $11     
         15        ASSIGN                                                   !4, $11
   20    16        INIT_FCALL                                               'var_dump'
         17        SEND_VAL                                                 '8.0.0'
         18        DO_ICALL                                                 
   22    19        ECHO                                                     '%3Cpre%3E'
   23    20        INIT_FCALL                                               'print_r'
         21        SEND_VAR                                                 !4
         22        DO_ICALL                                                 
   24    23        ECHO                                                     '%3C%2Fpre%3E'
   26    24        INIT_FCALL                                               'stream_get_wrappers'
         25        DO_ICALL                                         $15     
         26        ASSIGN                                                   !5, $15
   27    27        ECHO                                                     'openssl%3A+'
         28        INIT_FCALL                                               'extension_loaded'
         29        SEND_VAL                                                 'openssl'
         30        DO_ICALL                                         $17     
         31      > JMPZ                                                     $17, ->34
         32    >   QM_ASSIGN                                        ~18     'yes'
         33      > JMP                                                      ->35
         34    >   QM_ASSIGN                                        ~18     'no'
         35    >   ECHO                                                     ~18
         36        ECHO                                                     '%0A'
   28    37        ECHO                                                     'http+wrapper%3A+'
         38        INIT_FCALL                                               'in_array'
         39        SEND_VAL                                                 'http'
         40        SEND_VAR                                                 !5
         41        DO_ICALL                                         $19     
         42      > JMPZ                                                     $19, ->45
         43    >   QM_ASSIGN                                        ~20     'yes'
         44      > JMP                                                      ->46
         45    >   QM_ASSIGN                                        ~20     'no'
         46    >   ECHO                                                     ~20
         47        ECHO                                                     '%0A'
   29    48        ECHO                                                     'https+wrapper%3A+'
         49        INIT_FCALL                                               'in_array'
         50        SEND_VAL                                                 'https'
         51        SEND_VAR                                                 !5
         52        DO_ICALL                                         $21     
         53      > JMPZ                                                     $21, ->56
         54    >   QM_ASSIGN                                        ~22     'yes'
         55      > JMP                                                      ->57
         56    >   QM_ASSIGN                                        ~22     'no'
         57    >   ECHO                                                     ~22
         58        ECHO                                                     '%0A'
   30    59        ECHO                                                     'wrappers%3A+'
         60        INIT_FCALL                                               'var_dump'
         61        SEND_VAR                                                 !5
         62        DO_ICALL                                         $23     
         63        ECHO                                                     $23
   76    64      > RETURN                                                   1

Function api_call:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 114, Position 2 = 117
Branch analysis from position: 114
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 117
filename:       /in/6CZEC
function name:  api_call
number of ops:  122
compiled vars:  !0 = $action, !1 = $params, !2 = $token, !3 = $app_secret, !4 = $show_header, !5 = $api_url, !6 = $curl, !7 = $encoded_params, !8 = $signature_base, !9 = $api_signature, !10 = $response, !11 = $header_size, !12 = $header, !13 = $body
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
          4        RECV_INIT                                        !4      <false>
   36     5        CONCAT                                           ~14     'https%3A%2F%2Fapi.tme.eu%2F', !0
          6        CONCAT                                           ~15     ~14, '.json'
          7        ASSIGN                                                   !5, ~15
   37     8        INIT_FCALL_BY_NAME                                       'curl_init'
          9        DO_FCALL                                      0  $17     
         10        ASSIGN                                                   !6, $17
   40    11        ASSIGN_DIM                                               !1, 'Token'
         12        OP_DATA                                                  !2
   41    13        INIT_FCALL                                               'ksort'
         14        SEND_REF                                                 !1
         15        DO_ICALL                                                 
   44    16        INIT_FCALL                                               'str_replace'
   45    17        SEND_VAL                                                 <array>
   46    18        SEND_VAL                                                 <array>
   47    19        INIT_FCALL                                               'http_build_query'
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                         $21     
         22        SEND_VAR                                                 $21
         23        DO_ICALL                                         $22     
   44    24        ASSIGN                                                   !7, $22
   49    25        INIT_FCALL                                               'rawurlencode'
         26        SEND_VAR                                                 !5
         27        DO_ICALL                                         $24     
         28        CONCAT                                           ~25     'POST%26', $24
         29        CONCAT                                           ~26     ~25, '%26'
         30        INIT_FCALL                                               'rawurlencode'
         31        SEND_VAR                                                 !7
         32        DO_ICALL                                         $27     
         33        CONCAT                                           ~28     ~26, $27
         34        ASSIGN                                                   !8, ~28
   50    35        INIT_FCALL                                               'base64_encode'
         36        INIT_FCALL                                               'hash_hmac'
         37        SEND_VAL                                                 'sha1'
         38        SEND_VAR                                                 !8
         39        SEND_VAR                                                 !3
         40        SEND_VAL                                                 <true>
         41        DO_ICALL                                         $30     
         42        SEND_VAR                                                 $30
         43        DO_ICALL                                         $31     
         44        ASSIGN                                                   !9, $31
   52    45        ASSIGN_DIM                                               !1, 'ApiSignature'
         46        OP_DATA                                                  !9
   55    47        INIT_FCALL_BY_NAME                                       'curl_setopt'
         48        SEND_VAR_EX                                              !6
         49        FETCH_CONSTANT                                   ~34     'CURLOPT_URL'
         50        SEND_VAL_EX                                              ~34
         51        SEND_VAR_EX                                              !5
         52        DO_FCALL                                      0          
   56    53        INIT_FCALL_BY_NAME                                       'curl_setopt'
         54        SEND_VAR_EX                                              !6
         55        FETCH_CONSTANT                                   ~36     'CURLOPT_POST'
         56        SEND_VAL_EX                                              ~36
         57        SEND_VAL_EX                                              <true>
         58        DO_FCALL                                      0          
   57    59        INIT_FCALL_BY_NAME                                       'curl_setopt'
         60        SEND_VAR_EX                                              !6
         61        FETCH_CONSTANT                                   ~38     'CURLOPT_POSTFIELDS'
         62        SEND_VAL_EX                                              ~38
         63        INIT_FCALL                                               'http_build_query'
         64        SEND_VAR                                                 !1
         65        DO_ICALL                                         $39     
         66        SEND_VAR_NO_REF_EX                                       $39
         67        DO_FCALL                                      0          
   58    68        INIT_FCALL_BY_NAME                                       'curl_setopt'
         69        SEND_VAR_EX                                              !6
         70        FETCH_CONSTANT                                   ~41     'CURLOPT_RETURNTRANSFER'
         71        SEND_VAL_EX                                              ~41
         72        SEND_VAL_EX                                              <true>
         73        DO_FCALL                                      0          
   59    74        INIT_FCALL_BY_NAME                                       'curl_setopt'
         75        SEND_VAR_EX                                              !6
         76        FETCH_CONSTANT                                   ~43     'CURLOPT_SSL_VERIFYPEER'
         77        SEND_VAL_EX                                              ~43
         78        SEND_VAL_EX                                              <true>
         79        DO_FCALL                                      0          
   60    80        INIT_FCALL_BY_NAME                                       'curl_setopt'
         81        SEND_VAR_EX                                              !6
         82        FETCH_CONSTANT                                   ~45     'CURLOPT_VERBOSE'
         83        SEND_VAL_EX                                              ~45
         84        SEND_VAL_EX                                              1
         85        DO_FCALL                                      0          
   61    86        INIT_FCALL_BY_NAME                                       'curl_setopt'
         87        SEND_VAR_EX                                              !6
         88        FETCH_CONSTANT                                   ~47     'CURLOPT_HEADER'
         89        SEND_VAL_EX                                              ~47
         90        SEND_VAL_EX                                              1
         91        DO_FCALL                                      0          
   63    92        INIT_FCALL_BY_NAME                                       'curl_exec'
         93        SEND_VAR_EX                                              !6
         94        DO_FCALL                                      0  $49     
         95        ASSIGN                                                   !10, $49
   65    96        INIT_FCALL_BY_NAME                                       'curl_getinfo'
         97        SEND_VAR_EX                                              !6
         98        FETCH_CONSTANT                                   ~51     'CURLINFO_HEADER_SIZE'
         99        SEND_VAL_EX                                              ~51
        100        DO_FCALL                                      0  $52     
        101        ASSIGN                                                   !11, $52
   66   102        INIT_FCALL                                               'substr'
        103        SEND_VAR                                                 !10
        104        SEND_VAL                                                 0
        105        SEND_VAR                                                 !11
        106        DO_ICALL                                         $54     
        107        ASSIGN                                                   !12, $54
   67   108        INIT_FCALL                                               'substr'
        109        SEND_VAR                                                 !10
        110        SEND_VAR                                                 !11
        111        DO_ICALL                                         $56     
        112        ASSIGN                                                   !13, $56
   69   113      > JMPZ                                                     !4, ->117
   70   114    >   INIT_FCALL                                               'print_r'
        115        SEND_VAR                                                 !12
        116        DO_ICALL                                                 
   73   117    >   INIT_FCALL_BY_NAME                                       'curl_close'
        118        SEND_VAR_EX                                              !6
        119        DO_FCALL                                      0          
   75   120      > RETURN                                                   !13
   76   121*     > RETURN                                                   null

End of function api_call

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.27 ms | 1404 KiB | 39 Q