3v4l.org

run code in 300+ PHP versions simultaneously
<?php // key which will sign the data $key = hash('sha256', 'Unique user data or Some secret'); // the data $array = [ 'foobar' => 'baz' ]; // encode the payload $json = json_encode($array); // sign it with key $token = hash_hmac('sha256', $json, $key); // set response header //header('X-Checksum: '.$token); //echo $json; ## This is how the receiver would verify the received data. // faked: this would be populated by the request/response $_POST['json'] = $json; $_SERVER['X-Checksum'] = $token; // verify the data matches token by signing the data with the key $check = hash_hmac('sha256', $_POST['json'], $key); if (hash_equals($token, $check)) { echo 'Verified'; } else { echo 'Tampered'; } // example tampered data $_POST['json'] = 'tampered'.$json; $check = hash_hmac('sha256', $_POST['json'], $key); if (hash_equals($token, $check)) { echo 'Verified'; } else { echo 'Tampered'; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 57
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 55, Position 2 = 57
Branch analysis from position: 55
Branch analysis from position: 57
filename:       /in/tvUUR
function name:  (null)
number of ops:  59
compiled vars:  !0 = $key, !1 = $array, !2 = $json, !3 = $token, !4 = $check
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'hash'
          1        SEND_VAL                                                 'sha256'
          2        SEND_VAL                                                 'Unique+user+data+or+Some+secret'
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !0, $5
    6     5        ASSIGN                                                   !1, <array>
   11     6        INIT_FCALL                                               'json_encode'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $8      
          9        ASSIGN                                                   !2, $8
   14    10        INIT_FCALL                                               'hash_hmac'
         11        SEND_VAL                                                 'sha256'
         12        SEND_VAR                                                 !2
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $10     
         15        ASSIGN                                                   !3, $10
   24    16        FETCH_W                      global              $12     '_POST'
         17        ASSIGN_DIM                                               $12, 'json'
         18        OP_DATA                                                  !2
   25    19        FETCH_W                      global              $14     '_SERVER'
         20        ASSIGN_DIM                                               $14, 'X-Checksum'
         21        OP_DATA                                                  !3
   28    22        INIT_FCALL                                               'hash_hmac'
         23        SEND_VAL                                                 'sha256'
         24        FETCH_R                      global              ~16     '_POST'
         25        FETCH_DIM_R                                      ~17     ~16, 'json'
         26        SEND_VAL                                                 ~17
         27        SEND_VAR                                                 !0
         28        DO_ICALL                                         $18     
         29        ASSIGN                                                   !4, $18
   29    30        INIT_FCALL                                               'hash_equals'
         31        SEND_VAR                                                 !3
         32        SEND_VAR                                                 !4
         33        DO_ICALL                                         $20     
         34      > JMPZ                                                     $20, ->37
   30    35    >   ECHO                                                     'Verified'
         36      > JMP                                                      ->38
   32    37    >   ECHO                                                     'Tampered'
   36    38    >   CONCAT                                           ~23     'tampered', !2
         39        FETCH_W                      global              $21     '_POST'
         40        ASSIGN_DIM                                               $21, 'json'
         41        OP_DATA                                                  ~23
   38    42        INIT_FCALL                                               'hash_hmac'
         43        SEND_VAL                                                 'sha256'
         44        FETCH_R                      global              ~24     '_POST'
         45        FETCH_DIM_R                                      ~25     ~24, 'json'
         46        SEND_VAL                                                 ~25
         47        SEND_VAR                                                 !0
         48        DO_ICALL                                         $26     
         49        ASSIGN                                                   !4, $26
   39    50        INIT_FCALL                                               'hash_equals'
         51        SEND_VAR                                                 !3
         52        SEND_VAR                                                 !4
         53        DO_ICALL                                         $28     
         54      > JMPZ                                                     $28, ->57
   40    55    >   ECHO                                                     'Verified'
         56      > JMP                                                      ->58
   42    57    >   ECHO                                                     'Tampered'
   43    58    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.95 ms | 1400 KiB | 21 Q