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 // Add http if missing(to satisfy parse_url()) if (strpos($url, "/") !== 0 && strpos($url, "http") !== 0) { $url = 'http://' . $url; } $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', '()786754iusdafbiu767566&%€#'); 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/45O9H
function name:  (null)
number of ops:  12
compiled vars:  !0 = $domains, !1 = $domain
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   ASSIGN                                                   !0, <array>
   32     1      > FE_RESET_R                                       $3      !0, ->10
          2    > > FE_FETCH_R                                               $3, !1, ->10
   33     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                                                 
   32     9      > JMP                                                      ->2
         10    >   FE_FREE                                                  $3
   34    11      > RETURN                                                   1

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

End of function urlwhitelisted

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.52 ms | 1403 KiB | 24 Q