3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Check if a client IP is in our Server subnet * * @param string $client_ip * @param string $server_ip * @return boolean */ function clientInSameSubnet($client_ip=false,$server_ip=false) { if (!$client_ip) $client_ip = $_SERVER['REMOTE_ADDR']; if (!$server_ip) $server_ip = $_SERVER['SERVER_ADDR']; // Extract broadcast and netmask from ifconfig if (!($p = popen("ifconfig","r"))) return false; $out = ""; while(!feof($p)) $out .= fread($p,1024); fclose($p); // This is because the php.net comment function does not // allow long lines. $match = "/^.*".$server_ip; $match .= ".*Bcast:(\d{1,3}\.\d{1,3}i\.\d{1,3}\.\d{1,3}).*"; $match .= "Mask:(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/im"; if (!preg_match($match,$out,$regs)) return false; $bcast = ip2long($regs[1]); $smask = ip2long($regs[2]); $ipadr = ip2long($client_ip); $nmask = $bcast & $smask; return (($ipadr & $smask) == ($nmask & $smask)); } ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/bQmro
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E > > RETURN                                                   1

Function clientinsamesubnet:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 22
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 47
Branch analysis from position: 46
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 44) Position 1 = 32, Position 2 = 22
Branch analysis from position: 32
Branch analysis from position: 22
Branch analysis from position: 12
Branch analysis from position: 7
filename:       /in/bQmro
function name:  clientInSameSubnet
number of ops:  68
compiled vars:  !0 = $client_ip, !1 = $server_ip, !2 = $p, !3 = $out, !4 = $match, !5 = $regs, !6 = $bcast, !7 = $smask, !8 = $ipadr, !9 = $nmask
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV_INIT                                        !0      <false>
          1        RECV_INIT                                        !1      <false>
   10     2        BOOL_NOT                                         ~10     !0
          3      > JMPZ                                                     ~10, ->7
   11     4    >   FETCH_R                      global              ~11     '_SERVER'
          5        FETCH_DIM_R                                      ~12     ~11, 'REMOTE_ADDR'
          6        ASSIGN                                                   !0, ~12
   12     7    >   BOOL_NOT                                         ~14     !1
          8      > JMPZ                                                     ~14, ->12
   13     9    >   FETCH_R                      global              ~15     '_SERVER'
         10        FETCH_DIM_R                                      ~16     ~15, 'SERVER_ADDR'
         11        ASSIGN                                                   !1, ~16
   15    12    >   INIT_FCALL                                               'popen'
         13        SEND_VAL                                                 'ifconfig'
         14        SEND_VAL                                                 'r'
         15        DO_ICALL                                         $18     
         16        ASSIGN                                           ~19     !2, $18
         17        BOOL_NOT                                         ~20     ~19
         18      > JMPZ                                                     ~20, ->20
         19    > > RETURN                                                   <false>
   16    20    >   ASSIGN                                                   !3, ''
   17    21      > JMP                                                      ->27
   18    22    >   INIT_FCALL                                               'fread'
         23        SEND_VAR                                                 !2
         24        SEND_VAL                                                 1024
         25        DO_ICALL                                         $22     
         26        ASSIGN_OP                                     8          !3, $22
   17    27    >   INIT_FCALL                                               'feof'
         28        SEND_VAR                                                 !2
         29        DO_ICALL                                         $24     
         30        BOOL_NOT                                         ~25     $24
         31      > JMPNZ                                                    ~25, ->22
   19    32    >   INIT_FCALL                                               'fclose'
         33        SEND_VAR                                                 !2
         34        DO_ICALL                                                 
   22    35        CONCAT                                           ~27     '%2F%5E.%2A', !1
         36        ASSIGN                                                   !4, ~27
   23    37        ASSIGN_OP                                     8          !4, '.%2ABcast%3A%28%5Cd%7B1%2C3%7D%5C.%5Cd%7B1%2C3%7Di%5C.%5Cd%7B1%2C3%7D%5C.%5Cd%7B1%2C3%7D%29.%2A'
   24    38        ASSIGN_OP                                     8          !4, 'Mask%3A%28%5Cd%7B1%2C3%7D%5C.%5Cd%7B1%2C3%7D%5C.%5Cd%7B1%2C3%7D%5C.%5Cd%7B1%2C3%7D%29%24%2Fim'
   25    39        INIT_FCALL                                               'preg_match'
         40        SEND_VAR                                                 !4
         41        SEND_VAR                                                 !3
         42        SEND_REF                                                 !5
         43        DO_ICALL                                         $31     
         44        BOOL_NOT                                         ~32     $31
         45      > JMPZ                                                     ~32, ->47
   26    46    > > RETURN                                                   <false>
   27    47    >   INIT_FCALL                                               'ip2long'
         48        FETCH_DIM_R                                      ~33     !5, 1
         49        SEND_VAL                                                 ~33
         50        DO_ICALL                                         $34     
         51        ASSIGN                                                   !6, $34
   28    52        INIT_FCALL                                               'ip2long'
         53        FETCH_DIM_R                                      ~36     !5, 2
         54        SEND_VAL                                                 ~36
         55        DO_ICALL                                         $37     
         56        ASSIGN                                                   !7, $37
   29    57        INIT_FCALL                                               'ip2long'
         58        SEND_VAR                                                 !0
         59        DO_ICALL                                         $39     
         60        ASSIGN                                                   !8, $39
   30    61        BW_AND                                           ~41     !6, !7
         62        ASSIGN                                                   !9, ~41
   31    63        BW_AND                                           ~43     !8, !7
         64        BW_AND                                           ~44     !9, !7
         65        IS_EQUAL                                         ~45     ~43, ~44
         66      > RETURN                                                   ~45
   32    67*     > RETURN                                                   null

End of function clientinsamesubnet

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.89 ms | 1400 KiB | 25 Q