3v4l.org

run code in 300+ PHP versions simultaneously
<?php $mirror = "the.site-you-want-to-mirror.com"; // Change this value to the site you want to mirror. $req = $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . " HTTP/1.0\r\n"; $length = 0; foreach ($_SERVER as $k => $v) { if (substr($k, 0, 5) == "HTTP_") { $k = str_replace('_', ' ', substr($k, 5)); $k = str_replace(' ', '-', ucwords(strtolower($k))); if ($k == "Host") $v = $mirror; # Alter "Host" header to mirrored server if ($k == "Accept-Encoding") $v = "identity;q=1.0, *;q=0"; # Alter "Accept-Encoding" header to accept unencoded content only if ($k == "Keep-Alive") continue; # Drop "Keep-Alive" header if ($k == "Connection" && $v == "keep-alive") $v = "close"; # Alter value of "Connection" header from "keep-alive" to "close" $req .= $k . ": " . $v . "\r\n"; } } $body = @file_get_contents('php://input'); $req .= "Content-Type: " . $_SERVER['CONTENT_TYPE'] . "\r\n"; $req .= "Content-Length: " . strlen($body) . "\r\n"; $req .= "\r\n"; $req .= $body; #print $req; $fp = fsockopen($mirror, 80, $errno, $errmsg, 30); if (!$fp) { print "HTTP/1.0 502 Failed to connect remote server\r\n"; print "Content-Type: text/html\r\n\r\n"; print "<html><body>Failed to connect to $mirror due to:<br>[$errno] $errstr</body></html>"; exit; } fwrite($fp, $req); $headers_processed = 0; $reponse = ''; while (!feof($fp)) { $r = fread($fp, 8192); if (!$headers_processed) { $response .= $r; $nlnl = strpos($response, "\r\n\r\n"); $add = 4; if (!$nlnl) { $nlnl = strpos($response, "\n\n"); $add = 2; } if (!$nlnl) continue; $headers = substr($response, 0, $nlnl); $cookies = 'Set-Cookie: '; if (preg_match_all('/^(.*?)(\r?\n|$)/ims', $headers, $matches)) for ($i = 0; $i < count($matches[0]); ++$i) { $ct = $matches[1][$i]; # if (substr($ct, 0, 12) == "Set-Cookie: ") { # $cookies .= substr($ct, 12) . ','; # header($cookies); # } else header($ct, false); # print '>>' . $ct . "\r\n"; } print substr($response, $nlnl + $add); $headers_processed = 1; } else print $r; } fclose ($fp); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 63
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 63
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 62
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 46
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 49
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 52
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 52
2 jumps found. (Code = 46) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 58
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 58
Branch analysis from position: 56
Branch analysis from position: 49
Branch analysis from position: 46
Branch analysis from position: 62
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 91, Position 2 = 102
Branch analysis from position: 91
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 170
Branch analysis from position: 170
2 jumps found. (Code = 44) Position 1 = 175, Position 2 = 109
Branch analysis from position: 175
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 109
2 jumps found. (Code = 43) Position 1 = 116, Position 2 = 169
Branch analysis from position: 116
2 jumps found. (Code = 43) Position 1 = 125, Position 2 = 131
Branch analysis from position: 125
2 jumps found. (Code = 43) Position 1 = 133, Position 2 = 134
Branch analysis from position: 133
1 jumps found. (Code = 42) Position 1 = 170
Branch analysis from position: 170
Branch analysis from position: 134
2 jumps found. (Code = 43) Position 1 = 147, Position 2 = 161
Branch analysis from position: 147
1 jumps found. (Code = 42) Position 1 = 157
Branch analysis from position: 157
2 jumps found. (Code = 44) Position 1 = 161, Position 2 = 149
Branch analysis from position: 161
1 jumps found. (Code = 42) Position 1 = 170
Branch analysis from position: 170
Branch analysis from position: 149
2 jumps found. (Code = 44) Position 1 = 161, Position 2 = 149
Branch analysis from position: 161
Branch analysis from position: 149
Branch analysis from position: 161
Branch analysis from position: 131
Branch analysis from position: 169
2 jumps found. (Code = 44) Position 1 = 175, Position 2 = 109
Branch analysis from position: 175
Branch analysis from position: 109
Branch analysis from position: 63
filename:       /in/jYOo3
function name:  (null)
number of ops:  179
compiled vars:  !0 = $mirror, !1 = $req, !2 = $length, !3 = $v, !4 = $k, !5 = $body, !6 = $fp, !7 = $errno, !8 = $errmsg, !9 = $errstr, !10 = $headers_processed, !11 = $reponse, !12 = $r, !13 = $response, !14 = $nlnl, !15 = $add, !16 = $headers, !17 = $cookies, !18 = $matches, !19 = $i, !20 = $ct
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'the.site-you-want-to-mirror.com'
    5     1        FETCH_R                      global              ~22     '_SERVER'
          2        FETCH_DIM_R                                      ~23     ~22, 'REQUEST_METHOD'
          3        CONCAT                                           ~24     ~23, '+'
          4        FETCH_R                      global              ~25     '_SERVER'
          5        FETCH_DIM_R                                      ~26     ~25, 'REQUEST_URI'
          6        CONCAT                                           ~27     ~24, ~26
          7        CONCAT                                           ~28     ~27, '+HTTP%2F1.0%0D%0A'
          8        ASSIGN                                                   !1, ~28
    6     9        ASSIGN                                                   !2, 0
    7    10        FETCH_R                      global              ~31     '_SERVER'
         11      > FE_RESET_R                                       $32     ~31, ->63
         12    > > FE_FETCH_R                                       ~33     $32, !3, ->63
         13    >   ASSIGN                                                   !4, ~33
    8    14        INIT_FCALL                                               'substr'
         15        SEND_VAR                                                 !4
         16        SEND_VAL                                                 0
         17        SEND_VAL                                                 5
         18        DO_ICALL                                         $35     
         19        IS_EQUAL                                                 $35, 'HTTP_'
         20      > JMPZ                                                     ~36, ->62
    9    21    >   INIT_FCALL                                               'str_replace'
         22        SEND_VAL                                                 '_'
         23        SEND_VAL                                                 '+'
         24        INIT_FCALL                                               'substr'
         25        SEND_VAR                                                 !4
         26        SEND_VAL                                                 5
         27        DO_ICALL                                         $37     
         28        SEND_VAR                                                 $37
         29        DO_ICALL                                         $38     
         30        ASSIGN                                                   !4, $38
   10    31        INIT_FCALL                                               'str_replace'
         32        SEND_VAL                                                 '+'
         33        SEND_VAL                                                 '-'
         34        INIT_FCALL                                               'ucwords'
         35        INIT_FCALL                                               'strtolower'
         36        SEND_VAR                                                 !4
         37        DO_ICALL                                         $40     
         38        SEND_VAR                                                 $40
         39        DO_ICALL                                         $41     
         40        SEND_VAR                                                 $41
         41        DO_ICALL                                         $42     
         42        ASSIGN                                                   !4, $42
   11    43        IS_EQUAL                                                 !4, 'Host'
         44      > JMPZ                                                     ~44, ->46
   12    45    >   ASSIGN                                                   !3, !0
   13    46    >   IS_EQUAL                                                 !4, 'Accept-Encoding'
         47      > JMPZ                                                     ~46, ->49
   14    48    >   ASSIGN                                                   !3, 'identity%3Bq%3D1.0%2C+%2A%3Bq%3D0'
   15    49    >   IS_EQUAL                                                 !4, 'Keep-Alive'
         50      > JMPZ                                                     ~48, ->52
   16    51    > > JMP                                                      ->12
   17    52    >   IS_EQUAL                                         ~49     !4, 'Connection'
         53      > JMPZ_EX                                          ~49     ~49, ->56
         54    >   IS_EQUAL                                         ~50     !3, 'keep-alive'
         55        BOOL                                             ~49     ~50
         56    > > JMPZ                                                     ~49, ->58
   18    57    >   ASSIGN                                                   !3, 'close'
   19    58    >   CONCAT                                           ~52     !4, '%3A+'
         59        CONCAT                                           ~53     ~52, !3
         60        CONCAT                                           ~54     ~53, '%0D%0A'
         61        ASSIGN_OP                                     8          !1, ~54
    7    62    > > JMP                                                      ->12
         63    >   FE_FREE                                                  $32
   22    64        BEGIN_SILENCE                                    ~56     
         65        INIT_FCALL                                               'file_get_contents'
         66        SEND_VAL                                                 'php%3A%2F%2Finput'
         67        DO_ICALL                                         $57     
         68        END_SILENCE                                              ~56
         69        ASSIGN                                                   !5, $57
   23    70        FETCH_R                      global              ~59     '_SERVER'
         71        FETCH_DIM_R                                      ~60     ~59, 'CONTENT_TYPE'
         72        CONCAT                                           ~61     'Content-Type%3A+', ~60
         73        CONCAT                                           ~62     ~61, '%0D%0A'
         74        ASSIGN_OP                                     8          !1, ~62
   24    75        STRLEN                                           ~64     !5
         76        CONCAT                                           ~65     'Content-Length%3A+', ~64
         77        CONCAT                                           ~66     ~65, '%0D%0A'
         78        ASSIGN_OP                                     8          !1, ~66
   25    79        ASSIGN_OP                                     8          !1, '%0D%0A'
   26    80        ASSIGN_OP                                     8          !1, !5
   30    81        INIT_FCALL                                               'fsockopen'
         82        SEND_VAR                                                 !0
         83        SEND_VAL                                                 80
         84        SEND_REF                                                 !7
         85        SEND_REF                                                 !8
         86        SEND_VAL                                                 30
         87        DO_ICALL                                         $70     
         88        ASSIGN                                                   !6, $70
   31    89        BOOL_NOT                                         ~72     !6
         90      > JMPZ                                                     ~72, ->102
   32    91    >   ECHO                                                     'HTTP%2F1.0+502+Failed+to+connect+remote+server%0D%0A'
   33    92        ECHO                                                     'Content-Type%3A+text%2Fhtml%0D%0A%0D%0A'
   34    93        ROPE_INIT                                     7  ~74     '%3Chtml%3E%3Cbody%3EFailed+to+connect+to+'
         94        ROPE_ADD                                      1  ~74     ~74, !0
         95        ROPE_ADD                                      2  ~74     ~74, '+due+to%3A%3Cbr%3E%5B'
         96        ROPE_ADD                                      3  ~74     ~74, !7
         97        ROPE_ADD                                      4  ~74     ~74, '%5D+'
         98        ROPE_ADD                                      5  ~74     ~74, !9
         99        ROPE_END                                      6  ~73     ~74, '%3C%2Fbody%3E%3C%2Fhtml%3E'
        100        ECHO                                                     ~73
   35   101      > EXIT                                                     
   38   102    >   INIT_FCALL                                               'fwrite'
        103        SEND_VAR                                                 !6
        104        SEND_VAR                                                 !1
        105        DO_ICALL                                                 
   40   106        ASSIGN                                                   !10, 0
   41   107        ASSIGN                                                   !11, ''
   42   108      > JMP                                                      ->170
   43   109    >   INIT_FCALL                                               'fread'
        110        SEND_VAR                                                 !6
        111        SEND_VAL                                                 8192
        112        DO_ICALL                                         $81     
        113        ASSIGN                                                   !12, $81
   44   114        BOOL_NOT                                         ~83     !10
        115      > JMPZ                                                     ~83, ->169
   45   116    >   ASSIGN_OP                                     8          !13, !12
   46   117        INIT_FCALL                                               'strpos'
        118        SEND_VAR                                                 !13
        119        SEND_VAL                                                 '%0D%0A%0D%0A'
        120        DO_ICALL                                         $85     
        121        ASSIGN                                                   !14, $85
   47   122        ASSIGN                                                   !15, 4
   48   123        BOOL_NOT                                         ~88     !14
        124      > JMPZ                                                     ~88, ->131
   49   125    >   INIT_FCALL                                               'strpos'
        126        SEND_VAR                                                 !13
        127        SEND_VAL                                                 '%0A%0A'
        128        DO_ICALL                                         $89     
        129        ASSIGN                                                   !14, $89
   50   130        ASSIGN                                                   !15, 2
   52   131    >   BOOL_NOT                                         ~92     !14
        132      > JMPZ                                                     ~92, ->134
   53   133    > > JMP                                                      ->170
   54   134    >   INIT_FCALL                                               'substr'
        135        SEND_VAR                                                 !13
        136        SEND_VAL                                                 0
        137        SEND_VAR                                                 !14
        138        DO_ICALL                                         $93     
        139        ASSIGN                                                   !16, $93
   55   140        ASSIGN                                                   !17, 'Set-Cookie%3A+'
   56   141        INIT_FCALL                                               'preg_match_all'
        142        SEND_VAL                                                 '%2F%5E%28.%2A%3F%29%28%5Cr%3F%5Cn%7C%24%29%2Fims'
        143        SEND_VAR                                                 !16
        144        SEND_REF                                                 !18
        145        DO_ICALL                                         $96     
        146      > JMPZ                                                     $96, ->161
   57   147    >   ASSIGN                                                   !19, 0
        148      > JMP                                                      ->157
   58   149    >   FETCH_DIM_R                                      ~98     !18, 1
        150        FETCH_DIM_R                                      ~99     ~98, !19
        151        ASSIGN                                                   !20, ~99
   63   152        INIT_FCALL                                               'header'
        153        SEND_VAR                                                 !20
        154        SEND_VAL                                                 <false>
        155        DO_ICALL                                                 
   57   156        PRE_INC                                                  !19
        157    >   FETCH_DIM_R                                      ~103    !18, 0
        158        COUNT                                            ~104    ~103
        159        IS_SMALLER                                               !19, ~104
        160      > JMPNZ                                                    ~105, ->149
   66   161    >   INIT_FCALL                                               'substr'
        162        SEND_VAR                                                 !13
        163        ADD                                              ~106    !14, !15
        164        SEND_VAL                                                 ~106
        165        DO_ICALL                                         $107    
        166        ECHO                                                     $107
   67   167        ASSIGN                                                   !10, 1
        168      > JMP                                                      ->170
   69   169    >   ECHO                                                     !12
   42   170    >   INIT_FCALL                                               'feof'
        171        SEND_VAR                                                 !6
        172        DO_ICALL                                         $109    
        173        BOOL_NOT                                         ~110    $109
        174      > JMPNZ                                                    ~110, ->109
   71   175    >   INIT_FCALL                                               'fclose'
        176        SEND_VAR                                                 !6
        177        DO_ICALL                                                 
   72   178      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.84 ms | 1412 KiB | 39 Q