3v4l.org

run code in 300+ PHP versions simultaneously
<?php function urlWhitelisted($url) { $always_allowed = array('localhost'); $whitelisted_domains = array('fxnetworks.com') + $always_allowed; $domain = parse_url($url, PHP_URL_HOST); if (strpos($url, "/") === 0 || in_array($domain, $whitelisted_domains)) { return true; } foreach ($whitelisted_domains as $whitelisted_domain) { $whitelisted_domain = '.' . $whitelisted_domain; if (strpos($domain, $whitelisted_domain) === (strlen($domain) - strlen($whitelisted_domain))) { return true; } } return false; } $domains = array('/user', 'localhost/user', 'http://localhost:4039', 'http://fxnetworks.com/user', 'http://google.com'); foreach($domains as $domain) { var_dump(urlWhitelisted($domain)); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 10
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 10
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
filename:       /in/CiSY0
function name:  (null)
number of ops:  12
compiled vars:  !0 = $domains, !1 = $domain
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   ASSIGN                                                   !0, <array>
   26     1      > FE_RESET_R                                       $3      !0, ->10
          2    > > FE_FETCH_R                                               $3, !1, ->10
   27     3    >   INIT_FCALL                                               'var_dump'
          4        INIT_FCALL                                               'urlwhitelisted'
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
   26     9      > JMP                                                      ->2
         10    >   FE_FREE                                                  $3
   28    11      > RETURN                                                   1

Function urlwhitelisted:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 22
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 38
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 38
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 20
filename:       /in/CiSY0
function name:  urlWhitelisted
number of ops:  41
compiled vars:  !0 = $url, !1 = $always_allowed, !2 = $whitelisted_domains, !3 = $domain, !4 = $whitelisted_domain
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        ASSIGN                                                   !1, <array>
    6     2        ADD                                              ~6      <array>, !1
          3        ASSIGN                                                   !2, ~6
    8     4        INIT_FCALL                                               'parse_url'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $8      
          8        ASSIGN                                                   !3, $8
   10     9        INIT_FCALL                                               'strpos'
         10        SEND_VAR                                                 !0
         11        SEND_VAL                                                 '%2F'
         12        DO_ICALL                                         $10     
         13        IS_IDENTICAL                                     ~11     $10, 0
         14      > JMPNZ_EX                                         ~11     ~11, ->20
         15    >   INIT_FCALL                                               'in_array'
         16        SEND_VAR                                                 !3
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                         $12     
         19        BOOL                                             ~11     $12
         20    > > JMPZ                                                     ~11, ->22
   11    21    > > RETURN                                                   <true>
   14    22    > > FE_RESET_R                                       $13     !2, ->38
         23    > > FE_FETCH_R                                               $13, !4, ->38
   15    24    >   CONCAT                                           ~14     '.', !4
         25        ASSIGN                                                   !4, ~14
   16    26        INIT_FCALL                                               'strpos'
         27        SEND_VAR                                                 !3
         28        SEND_VAR                                                 !4
         29        DO_ICALL                                         $16     
         30        STRLEN                                           ~17     !3
         31        STRLEN                                           ~18     !4
         32        SUB                                              ~19     ~17, ~18
         33        IS_IDENTICAL                                             $16, ~19
         34      > JMPZ                                                     ~20, ->37
   17    35    >   FE_FREE                                                  $13
         36      > RETURN                                                   <true>
   14    37    > > JMP                                                      ->23
         38    >   FE_FREE                                                  $13
   21    39      > RETURN                                                   <false>
   22    40*     > RETURN                                                   null

End of function urlwhitelisted

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.83 ms | 1403 KiB | 22 Q