3v4l.org

run code in 300+ PHP versions simultaneously
<?php function redirect($url = '', array $params = array()) { // スキーム省略に対応 $url = preg_replace_callback( '@^/{2}(?!/)@', function ($matches) { return empty($_SERVER['HTTPS']) || strcasecmp($_SERVER['HTTPS'], 'off') ? 'http://' : 'https://' ; }, $url ); // URLをパースする if (!$p = parse_url($url)) { throw new BadMethodCallException('URLのパースに失敗しました'); } // 相対URLで書かれた場合には絶対URLに補正して再パースさせる if (!isset($p['host'])) { $url = rtrim($GLOBALS['SITE_URL'], '/') . '/' . ltrim($url, '/'); if (!$p = parse_url($url) or !isset($p['host']) or !isset($p['scheme'])) { throw new BadMethodCallException('URLのパースに失敗しました'); } } // クエリ―ストリングをパースして連想配列にする parse_str(isset($p['query']) ? $p['query'] : '', $query); // URLを組み立てていく $user_and_pass[] = isset($p['user']) ? $p['user'] : null; $user_and_pass[] = isset($p['pass']) ? $p['pass'] : null; $host_and_port[] = $p['host']; $host_and_port[] = isset($p['port']) ? $p['port'] : null; $server[] = implode(':', array_filter($user_and_pass, 'is_scalar')); $server[] = implode(':', array_filter($host_and_port, 'is_scalar')); $server_and_path[] = implode('@', array_filter($server, 'strlen')); $server_and_path[] = isset($p['path']) ? ltrim($p['path'], '/') : ''; $sp_and_query[] = implode('/', $server_and_path); $sp_and_query[] = http_build_query($params + $query, '', '&'); $spq_and_fragment[] = implode('?', array_filter($sp_and_query, 'strlen')); $spq_and_fragment[] = isset($p['fragment']) ? $p['fragment'] : null; $scheme_and_spqf[] = $p['scheme']; $scheme_and_spqf[] = implode('#', array_filter($spq_and_fragment, 'is_scalar')); $url = implode('://', $scheme_and_spqf); // 改行コードやNULLバイトを削除する $url = str_replace(array("\r", "\n", "\0"), '', $url); return $url; } $SITE_URL = '///user:' . "\n\0\n" . 'pass@exam' . "\n" . 'ple.com:87/p'."\n".'ublic'; var_dump(redirect("\n" . 'test.php?a=b'));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dJjAE
function name:  (null)
number of ops:  8
compiled vars:  !0 = $SITE_URL
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   50     0  E >   ASSIGN                                                   !0, '%2F%2F%2Fuser%3A%0A%00%0Apass%40exam%0Aple.com%3A87%2Fp%0Aublic'
   52     1        INIT_FCALL                                               'var_dump'
          2        INIT_FCALL                                               'redirect'
          3        SEND_VAL                                                 '%0Atest.php%3Fa%3Db'
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function redirect:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 53
Branch analysis from position: 22
2 jumps found. (Code = 47) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
2 jumps found. (Code = 47) Position 1 = 45, Position 2 = 48
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 49, Position 2 = 53
Branch analysis from position: 49
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 53
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 59
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 68
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 69
Branch analysis from position: 69
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 76
Branch analysis from position: 73
1 jumps found. (Code = 42) Position 1 = 77
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 87
Branch analysis from position: 84
1 jumps found. (Code = 42) Position 1 = 88
Branch analysis from position: 88
2 jumps found. (Code = 43) Position 1 = 122, Position 2 = 129
Branch analysis from position: 122
1 jumps found. (Code = 42) Position 1 = 130
Branch analysis from position: 130
2 jumps found. (Code = 43) Position 1 = 158, Position 2 = 161
Branch analysis from position: 158
1 jumps found. (Code = 42) Position 1 = 162
Branch analysis from position: 162
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 161
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 129
2 jumps found. (Code = 43) Position 1 = 158, Position 2 = 161
Branch analysis from position: 158
Branch analysis from position: 161
Branch analysis from position: 87
2 jumps found. (Code = 43) Position 1 = 122, Position 2 = 129
Branch analysis from position: 122
Branch analysis from position: 129
Branch analysis from position: 76
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 87
Branch analysis from position: 84
Branch analysis from position: 87
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 73, Position 2 = 76
Branch analysis from position: 73
Branch analysis from position: 76
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 65, Position 2 = 68
Branch analysis from position: 65
Branch analysis from position: 68
Branch analysis from position: 48
Branch analysis from position: 44
Branch analysis from position: 53
filename:       /in/dJjAE
function name:  redirect
number of ops:  190
compiled vars:  !0 = $url, !1 = $params, !2 = $p, !3 = $query, !4 = $user_and_pass, !5 = $host_and_port, !6 = $server, !7 = $server_and_path, !8 = $sp_and_query, !9 = $spq_and_fragment, !10 = $scheme_and_spqf
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV_INIT                                        !0      ''
          1        RECV_INIT                                        !1      <array>
    5     2        INIT_FCALL                                               'preg_replace_callback'
    6     3        SEND_VAL                                                 '%40%5E%2F%7B2%7D%28%3F%21%2F%29%40'
    7     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FdJjAE%3A7%240'
   13     5        SEND_VAL                                                 ~11
   14     6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $12     
    5     8        ASSIGN                                                   !0, $12
   17     9        INIT_FCALL                                               'parse_url'
         10        SEND_VAR                                                 !0
         11        DO_ICALL                                         $14     
         12        ASSIGN                                           ~15     !2, $14
         13        BOOL_NOT                                         ~16     ~15
         14      > JMPZ                                                     ~16, ->19
   18    15    >   NEW                                              $17     'BadMethodCallException'
         16        SEND_VAL_EX                                              'URL%E3%81%AE%E3%83%91%E3%83%BC%E3%82%B9%E3%81%AB%E5%A4%B1%E6%95%97%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F'
         17        DO_FCALL                                      0          
         18      > THROW                                         0          $17
   21    19    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~19     !2, 'host'
         20        BOOL_NOT                                         ~20     ~19
         21      > JMPZ                                                     ~20, ->53
   22    22    >   INIT_FCALL                                               'rtrim'
         23        FETCH_R                      global              ~21     'GLOBALS'
         24        FETCH_DIM_R                                      ~22     ~21, 'SITE_URL'
         25        SEND_VAL                                                 ~22
         26        SEND_VAL                                                 '%2F'
         27        DO_ICALL                                         $23     
         28        CONCAT                                           ~24     $23, '%2F'
         29        INIT_FCALL                                               'ltrim'
         30        SEND_VAR                                                 !0
         31        SEND_VAL                                                 '%2F'
         32        DO_ICALL                                         $25     
         33        CONCAT                                           ~26     ~24, $25
         34        ASSIGN                                                   !0, ~26
   23    35        INIT_FCALL                                               'parse_url'
         36        SEND_VAR                                                 !0
         37        DO_ICALL                                         $28     
         38        ASSIGN                                           ~29     !2, $28
         39        BOOL_NOT                                         ~30     ~29
         40      > JMPNZ_EX                                         ~30     ~30, ->44
         41    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~31     !2, 'host'
         42        BOOL_NOT                                         ~32     ~31
         43        BOOL                                             ~30     ~32
         44    > > JMPNZ_EX                                         ~30     ~30, ->48
         45    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~33     !2, 'scheme'
         46        BOOL_NOT                                         ~34     ~33
         47        BOOL                                             ~30     ~34
         48    > > JMPZ                                                     ~30, ->53
   24    49    >   NEW                                              $35     'BadMethodCallException'
         50        SEND_VAL_EX                                              'URL%E3%81%AE%E3%83%91%E3%83%BC%E3%82%B9%E3%81%AB%E5%A4%B1%E6%95%97%E3%81%97%E3%81%BE%E3%81%97%E3%81%9F'
         51        DO_FCALL                                      0          
         52      > THROW                                         0          $35
   28    53    >   INIT_FCALL                                               'parse_str'
         54        ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'query'
         55      > JMPZ                                                     ~37, ->59
         56    >   FETCH_DIM_R                                      ~38     !2, 'query'
         57        QM_ASSIGN                                        ~39     ~38
         58      > JMP                                                      ->60
         59    >   QM_ASSIGN                                        ~39     ''
         60    >   SEND_VAL                                                 ~39
         61        SEND_REF                                                 !3
         62        DO_ICALL                                                 
   30    63        ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'user'
         64      > JMPZ                                                     ~42, ->68
         65    >   FETCH_DIM_R                                      ~43     !2, 'user'
         66        QM_ASSIGN                                        ~44     ~43
         67      > JMP                                                      ->69
         68    >   QM_ASSIGN                                        ~44     null
         69    >   ASSIGN_DIM                                               !4
         70        OP_DATA                                                  ~44
   31    71        ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'pass'
         72      > JMPZ                                                     ~46, ->76
         73    >   FETCH_DIM_R                                      ~47     !2, 'pass'
         74        QM_ASSIGN                                        ~48     ~47
         75      > JMP                                                      ->77
         76    >   QM_ASSIGN                                        ~48     null
         77    >   ASSIGN_DIM                                               !4
         78        OP_DATA                                                  ~48
   32    79        FETCH_DIM_R                                      ~50     !2, 'host'
         80        ASSIGN_DIM                                               !5
         81        OP_DATA                                                  ~50
   33    82        ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'port'
         83      > JMPZ                                                     ~52, ->87
         84    >   FETCH_DIM_R                                      ~53     !2, 'port'
         85        QM_ASSIGN                                        ~54     ~53
         86      > JMP                                                      ->88
         87    >   QM_ASSIGN                                        ~54     null
         88    >   ASSIGN_DIM                                               !5
         89        OP_DATA                                                  ~54
   34    90        INIT_FCALL                                               'implode'
         91        SEND_VAL                                                 '%3A'
         92        INIT_FCALL                                               'array_filter'
         93        SEND_VAR                                                 !4
         94        SEND_VAL                                                 'is_scalar'
         95        DO_ICALL                                         $56     
         96        SEND_VAR                                                 $56
         97        DO_ICALL                                         $57     
         98        ASSIGN_DIM                                               !6
         99        OP_DATA                                                  $57
   35   100        INIT_FCALL                                               'implode'
        101        SEND_VAL                                                 '%3A'
        102        INIT_FCALL                                               'array_filter'
        103        SEND_VAR                                                 !5
        104        SEND_VAL                                                 'is_scalar'
        105        DO_ICALL                                         $59     
        106        SEND_VAR                                                 $59
        107        DO_ICALL                                         $60     
        108        ASSIGN_DIM                                               !6
        109        OP_DATA                                                  $60
   36   110        INIT_FCALL                                               'implode'
        111        SEND_VAL                                                 '%40'
        112        INIT_FCALL                                               'array_filter'
        113        SEND_VAR                                                 !6
        114        SEND_VAL                                                 'strlen'
        115        DO_ICALL                                         $62     
        116        SEND_VAR                                                 $62
        117        DO_ICALL                                         $63     
        118        ASSIGN_DIM                                               !7
        119        OP_DATA                                                  $63
   37   120        ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'path'
        121      > JMPZ                                                     ~65, ->129
        122    >   INIT_FCALL                                               'ltrim'
        123        FETCH_DIM_R                                      ~66     !2, 'path'
        124        SEND_VAL                                                 ~66
        125        SEND_VAL                                                 '%2F'
        126        DO_ICALL                                         $67     
        127        QM_ASSIGN                                        ~68     $67
        128      > JMP                                                      ->130
        129    >   QM_ASSIGN                                        ~68     ''
        130    >   ASSIGN_DIM                                               !7
        131        OP_DATA                                                  ~68
   38   132        INIT_FCALL                                               'implode'
        133        SEND_VAL                                                 '%2F'
        134        SEND_VAR                                                 !7
        135        DO_ICALL                                         $70     
        136        ASSIGN_DIM                                               !8
        137        OP_DATA                                                  $70
   39   138        INIT_FCALL                                               'http_build_query'
        139        ADD                                              ~72     !1, !3
        140        SEND_VAL                                                 ~72
        141        SEND_VAL                                                 ''
        142        SEND_VAL                                                 '%26'
        143        DO_ICALL                                         $73     
        144        ASSIGN_DIM                                               !8
        145        OP_DATA                                                  $73
   40   146        INIT_FCALL                                               'implode'
        147        SEND_VAL                                                 '%3F'
        148        INIT_FCALL                                               'array_filter'
        149        SEND_VAR                                                 !8
        150        SEND_VAL                                                 'strlen'
        151        DO_ICALL                                         $75     
        152        SEND_VAR                                                 $75
        153        DO_ICALL                                         $76     
        154        ASSIGN_DIM                                               !9
        155        OP_DATA                                                  $76
   41   156        ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'fragment'
        157      > JMPZ                                                     ~78, ->161
        158    >   FETCH_DIM_R                                      ~79     !2, 'fragment'
        159        QM_ASSIGN                                        ~80     ~79
        160      > JMP                                                      ->162
        161    >   QM_ASSIGN                                        ~80     null
        162    >   ASSIGN_DIM                                               !9
        163        OP_DATA                                                  ~80
   42   164        FETCH_DIM_R                                      ~82     !2, 'scheme'
        165        ASSIGN_DIM                                               !10
        166        OP_DATA                                                  ~82
   43   167        INIT_FCALL                                               'implode'
        168        SEND_VAL                                                 '%23'
        169        INIT_FCALL                                               'array_filter'
        170        SEND_VAR                                                 !9
        171        SEND_VAL                                                 'is_scalar'
        172        DO_ICALL                                         $84     
        173        SEND_VAR                                                 $84
        174        DO_ICALL                                         $85     
        175        ASSIGN_DIM                                               !10
        176        OP_DATA                                                  $85
   44   177        INIT_FCALL                                               'implode'
        178        SEND_VAL                                                 '%3A%2F%2F'
        179        SEND_VAR                                                 !10
        180        DO_ICALL                                         $86     
        181        ASSIGN                                                   !0, $86
   46   182        INIT_FCALL                                               'str_replace'
        183        SEND_VAL                                                 <array>
        184        SEND_VAL                                                 ''
        185        SEND_VAR                                                 !0
        186        DO_ICALL                                         $88     
        187        ASSIGN                                                   !0, $88
   47   188      > RETURN                                                   !0
   48   189*     > RETURN                                                   null

End of function redirect

Function %00%7Bclosure%7D%2Fin%2FdJjAE%3A7%240:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/dJjAE
function name:  {closure}
number of ops:  17
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
    9     1        FETCH_IS                                         ~1      '_SERVER'
          2        ISSET_ISEMPTY_DIM_OBJ                         1  ~2      ~1, 'HTTPS'
          3      > JMPNZ_EX                                         ~2      ~2, ->11
          4    >   INIT_FCALL                                               'strcasecmp'
          5        FETCH_R                      global              ~3      '_SERVER'
          6        FETCH_DIM_R                                      ~4      ~3, 'HTTPS'
          7        SEND_VAL                                                 ~4
          8        SEND_VAL                                                 'off'
          9        DO_ICALL                                         $5      
         10        BOOL                                             ~2      $5
         11    > > JMPZ                                                     ~2, ->14
   10    12    >   QM_ASSIGN                                        ~6      'http%3A%2F%2F'
         13      > JMP                                                      ->15
   11    14    >   QM_ASSIGN                                        ~6      'https%3A%2F%2F'
         15    > > RETURN                                                   ~6
   13    16*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FdJjAE%3A7%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.29 ms | 1410 KiB | 36 Q