3v4l.org

run code in 300+ PHP versions simultaneously
<?php function urlWhitelisted($url) { $always_allowed = array('localhost'); $whitelisted_domains = array_merge(array('somedomain.com'), $always_allowed); // partly snatched from https://gist.github.com/mjangda/1623788 $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://somedomain.com/user', 'http://google.com', 'google.com', 'somedomain.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/Ru2R8
function name:  (null)
number of ops:  12
compiled vars:  !0 = $domains, !1 = $domain
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, <array>
   28     1      > FE_RESET_R                                       $3      !0, ->10
          2    > > FE_FETCH_R                                               $3, !1, ->10
   29     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                                                 
   28     9      > JMP                                                      ->2
         10    >   FE_FREE                                                  $3
   30    11      > RETURN                                                   1

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

End of function urlwhitelisted

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.77 ms | 1394 KiB | 24 Q