3v4l.org

run code in 300+ PHP versions simultaneously
<?php function urlWhitelisted($url) { $always_allowed = array('localhost'); $whitelisted_domains = array('fxnetworks.com') + $always_allowed; if (strpos($url, "/") !== 0 && strpos($url, "http") !== 0) { $url = 'http://' . $url; } $domain = parse_url($url, PHP_URL_HOST); var_dump($domain); 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', 'google.com', 'fxnetworks.com.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/3CXJu
function name:  (null)
number of ops:  12
compiled vars:  !0 = $domains, !1 = $domain
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, <array>
   30     1      > FE_RESET_R                                       $3      !0, ->10
          2    > > FE_FETCH_R                                               $3, !1, ->10
   31     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                                                 
   30     9      > JMP                                                      ->2
         10    >   FE_FREE                                                  $3
   32    11      > RETURN                                                   1

Function urlwhitelisted:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 47) Position 1 = 33, Position 2 = 38
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 40
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
2 jumps found. (Code = 77) Position 1 = 41, Position 2 = 56
Branch analysis from position: 41
2 jumps found. (Code = 78) Position 1 = 42, Position 2 = 56
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 55
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
Branch analysis from position: 38
Branch analysis from position: 19
Branch analysis from position: 16
filename:       /in/3CXJu
function name:  urlWhitelisted
number of ops:  59
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                                               'strpos'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 '%2F'
          7        DO_ICALL                                         $8      
          8        IS_NOT_IDENTICAL                                 ~9      $8, 0
          9      > JMPZ_EX                                          ~9      ~9, ->16
         10    >   INIT_FCALL                                               'strpos'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 'http'
         13        DO_ICALL                                         $10     
         14        IS_NOT_IDENTICAL                                 ~11     $10, 0
         15        BOOL                                             ~9      ~11
         16    > > JMPZ                                                     ~9, ->19
    9    17    >   CONCAT                                           ~12     'http%3A%2F%2F', !0
         18        ASSIGN                                                   !0, ~12
   11    19    >   INIT_FCALL                                               'parse_url'
         20        SEND_VAR                                                 !0
         21        SEND_VAL                                                 1
         22        DO_ICALL                                         $14     
         23        ASSIGN                                                   !3, $14
   12    24        INIT_FCALL                                               'var_dump'
         25        SEND_VAR                                                 !3
         26        DO_ICALL                                                 
   14    27        INIT_FCALL                                               'strpos'
         28        SEND_VAR                                                 !0
         29        SEND_VAL                                                 '%2F'
         30        DO_ICALL                                         $17     
         31        IS_IDENTICAL                                     ~18     $17, 0
         32      > JMPNZ_EX                                         ~18     ~18, ->38
         33    >   INIT_FCALL                                               'in_array'
         34        SEND_VAR                                                 !3
         35        SEND_VAR                                                 !2
         36        DO_ICALL                                         $19     
         37        BOOL                                             ~18     $19
         38    > > JMPZ                                                     ~18, ->40
   15    39    > > RETURN                                                   <true>
   18    40    > > FE_RESET_R                                       $20     !2, ->56
         41    > > FE_FETCH_R                                               $20, !4, ->56
   19    42    >   CONCAT                                           ~21     '.', !4
         43        ASSIGN                                                   !4, ~21
   20    44        INIT_FCALL                                               'strpos'
         45        SEND_VAR                                                 !3
         46        SEND_VAR                                                 !4
         47        DO_ICALL                                         $23     
         48        STRLEN                                           ~24     !3
         49        STRLEN                                           ~25     !4
         50        SUB                                              ~26     ~24, ~25
         51        IS_IDENTICAL                                             $23, ~26
         52      > JMPZ                                                     ~27, ->55
   21    53    >   FE_FREE                                                  $20
         54      > RETURN                                                   <true>
   18    55    > > JMP                                                      ->41
         56    >   FE_FREE                                                  $20
   25    57      > RETURN                                                   <false>
   26    58*     > RETURN                                                   null

End of function urlwhitelisted

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.86 ms | 1403 KiB | 22 Q