3v4l.org

run code in 300+ PHP versions simultaneously
<?php function write_log($txt) { file_put_contents("put_log.txt", $txt); chmod("put_log.txt", 0666); } require 'dauth.php'; // customize the following defines:- define('AUTH_REALM', 'myserver/mydirectory'); define('URL_BASE', 'http://myserver/mydirectory'); /* --- The following sample authorization function uses an array of user names and passwords defined and fixed here. An actual implementation might read the array from an external resource. The use of an ArrayIterator makes it moderately easy to extend this mechanism. --- */ function authorize() { $auth = new authorizer(AUTH_REALM, new ArrayIterator(array('user1' => 'password1', 'user2' => 'password2'))); $auth->check(); // dies if not OK } function puterror($status, $body, $log = FALSE) { header ("HTTP/1.1 $status"); if ($log) write_log($log); die("<html><head><title>Error $status</title></head><body>$body</body></html>"); } function putfile() { $f = pathinfo($fname = $_SERVER['REQUEST_URI']); if ($f['extension'] != 'html') puterror('403 Forbidden', "Bad file type in $fname"); $f = fopen($fname = $f['basename'], 'w'); if (!$f) puterror('409 Create error', "Couldn't create file"); $s = fopen('php://input', 'r'); // read from standard input if (!$s) puterror('404 Input Unavailable', "Couldn't open input"); while($kb = fread($s, 1024)) fwrite($f, $kb, 1024); fclose($f); fclose($s); chmod($fname, 0666); $fname = URL_BASE . $fname; header("Location: $fname"); header("HTTP/1.1 201 Created"); echo "<html><head><title>Success</title></head><body>"; echo "<p>Created <a href='$fname'>$fname</a> OK.</p></body></html>"; } if ($_SERVER['REQUEST_METHOD'] != 'PUT') header("HTTP/1.1 403 Bad Request"); else { authorize(); putfile(); // uncommment the next line to debug misbehaviour //write_log(date('c') . "\n" . $_SERVER['REQUEST_URI'] . "\nStatus: $retcode; } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ha6aa
function name:  (null)
number of ops:  22
compiled vars:  !0 = $retcode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   INCLUDE_OR_EVAL                                          'dauth.php', REQUIRE
    8     1        INIT_FCALL                                               'define'
          2        SEND_VAL                                                 'AUTH_REALM'
          3        SEND_VAL                                                 'myserver%2Fmydirectory'
          4        DO_ICALL                                                 
    9     5        INIT_FCALL                                               'define'
          6        SEND_VAL                                                 'URL_BASE'
          7        SEND_VAL                                                 'http%3A%2F%2Fmyserver%2Fmydirectory'
          8        DO_ICALL                                                 
   53     9        FETCH_R                      global              ~4      '_SERVER'
         10        FETCH_DIM_R                                      ~5      ~4, 'REQUEST_METHOD'
         11        IS_NOT_EQUAL                                             ~5, 'PUT'
         12      > JMPZ                                                     ~6, ->17
   54    13    >   INIT_FCALL                                               'header'
         14        SEND_VAL                                                 'HTTP%2F1.1+403+Bad+Request'
         15        DO_ICALL                                                 
         16      > JMP                                                      ->21
   56    17    >   INIT_FCALL                                               'authorize'
         18        DO_FCALL                                      0          
   57    19        INIT_FCALL                                               'putfile'
         20        DO_FCALL                                      0          
   62    21    > > RETURN                                                   1

Function write_log:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ha6aa
function name:  write_log
number of ops:  10
compiled vars:  !0 = $txt
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        INIT_FCALL                                               'file_put_contents'
          2        SEND_VAL                                                 'put_log.txt'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                                 
    4     5        INIT_FCALL                                               'chmod'
          6        SEND_VAL                                                 'put_log.txt'
          7        SEND_VAL                                                 438
          8        DO_ICALL                                                 
    5     9      > RETURN                                                   null

End of function write_log

Function authorize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ha6aa
function name:  authorize
number of ops:  12
compiled vars:  !0 = $auth
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   NEW                                              $1      'authorizer'
          1        FETCH_CONSTANT                                   ~2      'AUTH_REALM'
          2        SEND_VAL_EX                                              ~2
          3        NEW                                              $3      'ArrayIterator'
   23     4        SEND_VAL_EX                                              <array>
          5        DO_FCALL                                      0          
          6        SEND_VAR_NO_REF_EX                                       $3
          7        DO_FCALL                                      0          
   22     8        ASSIGN                                                   !0, $1
   24     9        INIT_METHOD_CALL                                         !0, 'check'
         10        DO_FCALL                                      0          
   25    11      > RETURN                                                   null

End of function authorize

Function puterror:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 12
filename:       /in/Ha6aa
function name:  puterror
number of ops:  19
compiled vars:  !0 = $status, !1 = $body, !2 = $log
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <false>
   28     3        INIT_FCALL                                               'header'
          4        NOP                                                      
          5        FAST_CONCAT                                      ~3      'HTTP%2F1.1+', !0
          6        SEND_VAL                                                 ~3
          7        DO_ICALL                                                 
   29     8      > JMPZ                                                     !2, ->12
          9    >   INIT_FCALL                                               'write_log'
         10        SEND_VAR                                                 !2
         11        DO_FCALL                                      0          
   30    12    >   ROPE_INIT                                     5  ~7      '%3Chtml%3E%3Chead%3E%3Ctitle%3EError%0A'
   31    13        ROPE_ADD                                      1  ~7      ~7, !0
         14        ROPE_ADD                                      2  ~7      ~7, '%3C%2Ftitle%3E%3C%2Fhead%3E%3Cbody%3E'
         15        ROPE_ADD                                      3  ~7      ~7, !1
         16        ROPE_END                                      4  ~6      ~7, '%3C%2Fbody%3E%3C%2Fhtml%3E'
         17      > EXIT                                                     ~6
   32    18*     > RETURN                                                   null

End of function puterror

Function putfile:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 29
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 40
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 46
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 41
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 41
Branch analysis from position: 52
Branch analysis from position: 41
Branch analysis from position: 40
Branch analysis from position: 29
Branch analysis from position: 16
filename:       /in/Ha6aa
function name:  putfile
number of ops:  81
compiled vars:  !0 = $f, !1 = $fname, !2 = $s, !3 = $kb
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                               'pathinfo'
          1        FETCH_R                      global              ~4      '_SERVER'
          2        FETCH_DIM_R                                      ~5      ~4, 'REQUEST_URI'
          3        ASSIGN                                           ~6      !1, ~5
          4        SEND_VAL                                                 ~6
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !0, $7
   36     7        FETCH_DIM_R                                      ~9      !0, 'extension'
          8        IS_NOT_EQUAL                                             ~9, 'html'
          9      > JMPZ                                                     ~10, ->16
         10    >   INIT_FCALL                                               'puterror'
         11        SEND_VAL                                                 '403+Forbidden'
         12        NOP                                                      
   37    13        FAST_CONCAT                                      ~11     'Bad+file%0Atype+in+', !1
         14        SEND_VAL                                                 ~11
         15        DO_FCALL                                      0          
   38    16    >   INIT_FCALL                                               'fopen'
         17        FETCH_DIM_R                                      ~13     !0, 'basename'
         18        ASSIGN                                           ~14     !1, ~13
         19        SEND_VAL                                                 ~14
         20        SEND_VAL                                                 'w'
         21        DO_ICALL                                         $15     
         22        ASSIGN                                                   !0, $15
   39    23        BOOL_NOT                                         ~17     !0
         24      > JMPZ                                                     ~17, ->29
         25    >   INIT_FCALL                                               'puterror'
         26        SEND_VAL                                                 '409+Create+error'
         27        SEND_VAL                                                 'Couldn%27t+create+file'
         28        DO_FCALL                                      0          
   40    29    >   INIT_FCALL                                               'fopen'
         30        SEND_VAL                                                 'php%3A%2F%2Finput'
         31        SEND_VAL                                                 'r'
         32        DO_ICALL                                         $19     
         33        ASSIGN                                                   !2, $19
   41    34        BOOL_NOT                                         ~21     !2
         35      > JMPZ                                                     ~21, ->40
         36    >   INIT_FCALL                                               'puterror'
         37        SEND_VAL                                                 '404+Input+Unavailable'
         38        SEND_VAL                                                 'Couldn%27t+open+input'
         39        DO_FCALL                                      0          
   42    40    > > JMP                                                      ->46
         41    >   INIT_FCALL                                               'fwrite'
         42        SEND_VAR                                                 !0
         43        SEND_VAR                                                 !3
         44        SEND_VAL                                                 1024
         45        DO_ICALL                                                 
         46    >   INIT_FCALL                                               'fread'
         47        SEND_VAR                                                 !2
         48        SEND_VAL                                                 1024
         49        DO_ICALL                                         $24     
         50        ASSIGN                                           ~25     !3, $24
         51      > JMPNZ                                                    ~25, ->41
   43    52    >   INIT_FCALL                                               'fclose'
         53        SEND_VAR                                                 !0
         54        DO_ICALL                                                 
   44    55        INIT_FCALL                                               'fclose'
         56        SEND_VAR                                                 !2
         57        DO_ICALL                                                 
   45    58        INIT_FCALL                                               'chmod'
         59        SEND_VAR                                                 !1
         60        SEND_VAL                                                 438
         61        DO_ICALL                                                 
   46    62        FETCH_CONSTANT                                   ~29     'URL_BASE'
         63        CONCAT                                           ~30     ~29, !1
         64        ASSIGN                                                   !1, ~30
   47    65        INIT_FCALL                                               'header'
         66        NOP                                                      
         67        FAST_CONCAT                                      ~32     'Location%3A+', !1
         68        SEND_VAL                                                 ~32
         69        DO_ICALL                                                 
   48    70        INIT_FCALL                                               'header'
         71        SEND_VAL                                                 'HTTP%2F1.1+201+Created'
         72        DO_ICALL                                                 
   49    73        ECHO                                                     '%3Chtml%3E%3Chead%3E%3Ctitle%3ESuccess%3C%2Ftitle%3E%3C%2Fhead%3E%3Cbody%3E'
   50    74        ROPE_INIT                                     5  ~36     '%3Cp%3ECreated+%3Ca+href%3D%27'
         75        ROPE_ADD                                      1  ~36     ~36, !1
         76        ROPE_ADD                                      2  ~36     ~36, '%27%3E'
         77        ROPE_ADD                                      3  ~36     ~36, !1
         78        ROPE_END                                      4  ~35     ~36, '%3C%2Fa%3E+OK.%3C%2Fp%3E%3C%2Fbody%3E%3C%2Fhtml%3E'
         79        ECHO                                                     ~35
   51    80      > RETURN                                                   null

End of function putfile

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.92 ms | 1402 KiB | 37 Q