3v4l.org

run code in 500+ PHP versions simultaneously
<?php $email = 'email@example.com'; function base64url_encode($str) { return rtrim(strtr(base64_encode($str), '+/', '-_'), '='); } function base64url_decode($str) { return base64_decode(strtr($str, '-_', '+/')); } $token = base64url_encode($email).'.'.hash_hmac('sha256', 'email@example.com', 'secret-server-key'); // mock got token $_GET['token'] = $token; // when checking if (isset($_GET['token'])) { $tok = explode('.', $_GET['token']); // check token parts if (count($tok) !== 2) { // not valid token throw new \Exception('Invalid token!'); } // check email segment if (!isset($tok[0]) || !filter_var(base64url_decode($tok[0]), FILTER_VALIDATE_EMAIL)) { // not valid email throw new \Exception('Invalid token!'); } $email = base64url_decode($tok[0]); if ($tok[1] !== hash_hmac('sha256', $email, 'secret-server-key')) { // failed verification throw new \Exception('Invalid token!'); } // echo 'Its lagit!'; // do somthing with $email }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 68
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 32
2 jumps found. (Code = 47) Position 1 = 35, Position 2 = 45
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 50
Branch analysis from position: 46
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 67
Branch analysis from position: 63
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 67
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
Branch analysis from position: 68
filename:       /in/tcqk8
function name:  (null)
number of ops:  69
compiled vars:  !0 = $email, !1 = $token, !2 = $tok
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, 'email%40example.com'
   12     1        INIT_FCALL                                                   'base64url_encode'
          2        SEND_VAR                                                     !0
          3        DO_FCALL                                          0  $4      
          4        CONCAT                                               ~5      $4, '.'
          5        INIT_FCALL                                                   'hash_hmac'
          6        SEND_VAL                                                     'sha256'
          7        SEND_VAL                                                     'email%40example.com'
          8        SEND_VAL                                                     'secret-server-key'
          9        DO_ICALL                                             $6      
         10        CONCAT                                               ~7      ~5, $6
         11        ASSIGN                                                       !1, ~7
   15    12        FETCH_W                          global              $9      '_GET'
         13        ASSIGN_DIM                                                   $9, 'token'
         14        OP_DATA                                                      !1
   18    15        FETCH_IS                                             ~11     '_GET'
         16        ISSET_ISEMPTY_DIM_OBJ                             0          ~11, 'token'
         17      > JMPZ                                                         ~12, ->68
   19    18    >   INIT_FCALL                                                   'explode'
         19        SEND_VAL                                                     '.'
         20        FETCH_R                          global              ~13     '_GET'
         21        FETCH_DIM_R                                          ~14     ~13, 'token'
         22        SEND_VAL                                                     ~14
         23        DO_ICALL                                             $15     
         24        ASSIGN                                                       !2, $15
   22    25        COUNT                                                ~17     !2
         26        IS_NOT_IDENTICAL                                             ~17, 2
         27      > JMPZ                                                         ~18, ->32
   24    28    >   NEW                                                  $19     'Exception'
         29        SEND_VAL_EX                                                  'Invalid+token%21'
         30        DO_FCALL                                          0          
         31      > THROW                                             0          $19
   28    32    >   ISSET_ISEMPTY_DIM_OBJ                             0  ~21     !2, 0
         33        BOOL_NOT                                             ~22     ~21
         34      > JMPNZ_EX                                             ~22     ~22, ->45
         35    >   INIT_FCALL                                                   'filter_var'
         36        INIT_FCALL                                                   'base64url_decode'
         37        FETCH_DIM_R                                          ~23     !2, 0
         38        SEND_VAL                                                     ~23
         39        DO_FCALL                                          0  $24     
         40        SEND_VAR                                                     $24
         41        SEND_VAL                                                     274
         42        DO_ICALL                                             $25     
         43        BOOL_NOT                                             ~26     $25
         44        BOOL                                                 ~22     ~26
         45    > > JMPZ                                                         ~22, ->50
   30    46    >   NEW                                                  $27     'Exception'
         47        SEND_VAL_EX                                                  'Invalid+token%21'
         48        DO_FCALL                                          0          
         49      > THROW                                             0          $27
   33    50    >   INIT_FCALL                                                   'base64url_decode'
         51        FETCH_DIM_R                                          ~29     !2, 0
         52        SEND_VAL                                                     ~29
         53        DO_FCALL                                          0  $30     
         54        ASSIGN                                                       !0, $30
   35    55        FETCH_DIM_R                                          ~32     !2, 1
         56        INIT_FCALL                                                   'hash_hmac'
         57        SEND_VAL                                                     'sha256'
         58        SEND_VAR                                                     !0
         59        SEND_VAL                                                     'secret-server-key'
         60        DO_ICALL                                             $33     
         61        IS_NOT_IDENTICAL                                             $33, ~32
         62      > JMPZ                                                         ~34, ->67
   37    63    >   NEW                                                  $35     'Exception'
         64        SEND_VAL_EX                                                  'Invalid+token%21'
         65        DO_FCALL                                          0          
         66      > THROW                                             0          $35
   41    67    >   ECHO                                                         'Its+lagit%21'
   44    68    > > RETURN                                                       1

Function base64url_encode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tcqk8
function name:  base64url_encode
number of ops:  12
compiled vars:  !0 = $str
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
    5     1        INIT_FCALL                                                   'rtrim'
          2        INIT_FCALL                                                   'base64_encode'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                             $1      
          5        FRAMELESS_ICALL_3                strtr               ~2      $1, '%2B%2F'
          6        OP_DATA                                                      '-_'
          7        SEND_VAL                                                     ~2
          8        SEND_VAL                                                     '%3D'
          9        DO_ICALL                                             $3      
         10      > RETURN                                                       $3
    6    11*     > RETURN                                                       null

End of function base64url_encode

Function base64url_decode:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/tcqk8
function name:  base64url_decode
number of ops:  8
compiled vars:  !0 = $str
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
    9     1        INIT_FCALL                                                   'base64_decode'
          2        FRAMELESS_ICALL_3                strtr               ~1      !0, '-_'
          3        OP_DATA                                                      '%2B%2F'
          4        SEND_VAL                                                     ~1
          5        DO_ICALL                                             $2      
          6      > RETURN                                                       $2
   10     7*     > RETURN                                                       null

End of function base64url_decode

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.76 ms | 2020 KiB | 22 Q