3v4l.org

run code in 300+ PHP versions simultaneously
<?php function ip_info($ip = NULL, $purpose = "location", $deep_detect = TRUE) { $output = NULL; if (filter_var($ip, FILTER_VALIDATE_IP) === FALSE) { $ip = $_SERVER["REMOTE_ADDR"]; if ($deep_detect) { if (filter_var(@$_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; if (filter_var(@$_SERVER['HTTP_CLIENT_IP'], FILTER_VALIDATE_IP)) $ip = $_SERVER['HTTP_CLIENT_IP']; } } $purpose = str_replace(array("name", "\n", "\t", " ", "-", "_"), NULL, strtolower(trim($purpose))); $support = array("country", "countrycode", "state", "region", "city", "location", "address"); $continents = array( "AF" => "Africa", "AN" => "Antarctica", "AS" => "Asia", "EU" => "Europe", "OC" => "Australia (Oceania)", "NA" => "North America", "SA" => "South America" ); if (filter_var($ip, FILTER_VALIDATE_IP) && in_array($purpose, $support)) { $ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $ip)); if (@strlen(trim($ipdat->geoplugin_countryCode)) == 2) { switch ($purpose) { case "location": $output = array( "city" => @$ipdat->geoplugin_city, "state" => @$ipdat->geoplugin_regionName, "country" => @$ipdat->geoplugin_countryName, "country_code" => @$ipdat->geoplugin_countryCode, "continent" => @$continents[strtoupper($ipdat->geoplugin_continentCode)], "continent_code" => @$ipdat->geoplugin_continentCode ); break; case "address": $address = array($ipdat->geoplugin_countryName); if (@strlen($ipdat->geoplugin_regionName) >= 1) $address[] = $ipdat->geoplugin_regionName; if (@strlen($ipdat->geoplugin_city) >= 1) $address[] = $ipdat->geoplugin_city; $output = implode(", ", array_reverse($address)); break; case "city": $output = @$ipdat->geoplugin_city; break; case "state": $output = @$ipdat->geoplugin_regionName; break; case "region": $output = @$ipdat->geoplugin_regionName; break; case "country": $output = @$ipdat->geoplugin_countryName; break; case "countrycode": $output = @$ipdat->geoplugin_countryCode; break; } } } return $output; } $ipinfo = ip_info($_SERVER['REMOTE_ADDR']); echo $ipinfo['country_code'];
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9go2v
function name:  (null)
number of ops:  9
compiled vars:  !0 = $ipinfo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   66     0  E >   INIT_FCALL                                               'ip_info'
          1        FETCH_R                      global              ~1      '_SERVER'
          2        FETCH_DIM_R                                      ~2      ~1, 'REMOTE_ADDR'
          3        SEND_VAL                                                 ~2
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !0, $3
   67     6        FETCH_DIM_R                                      ~5      !0, 'country_code'
          7        ECHO                                                     ~5
          8      > RETURN                                                   1

Function ip_info:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 38
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 38
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 26
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
2 jumps found. (Code = 46) Position 1 = 57, Position 2 = 62
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 183
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 183
Branch analysis from position: 82
9 jumps found. (Code = 188) Position 1 = 98, Position 2 = 128, Position 3 = 158, Position 4 = 163, Position 5 = 168, Position 6 = 173, Position 7 = 178, Position 8 = 183, Position 9 = 83
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 183
Branch analysis from position: 183
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 128
2 jumps found. (Code = 43) Position 1 = 137, Position 2 = 140
Branch analysis from position: 137
2 jumps found. (Code = 43) Position 1 = 146, Position 2 = 149
Branch analysis from position: 146
1 jumps found. (Code = 42) Position 1 = 183
Branch analysis from position: 183
Branch analysis from position: 149
Branch analysis from position: 140
Branch analysis from position: 158
1 jumps found. (Code = 42) Position 1 = 183
Branch analysis from position: 183
Branch analysis from position: 163
1 jumps found. (Code = 42) Position 1 = 183
Branch analysis from position: 183
Branch analysis from position: 168
1 jumps found. (Code = 42) Position 1 = 183
Branch analysis from position: 183
Branch analysis from position: 173
1 jumps found. (Code = 42) Position 1 = 183
Branch analysis from position: 183
Branch analysis from position: 178
1 jumps found. (Code = 42) Position 1 = 183
Branch analysis from position: 183
Branch analysis from position: 183
Branch analysis from position: 83
2 jumps found. (Code = 44) Position 1 = 85, Position 2 = 98
Branch analysis from position: 85
2 jumps found. (Code = 44) Position 1 = 87, Position 2 = 128
Branch analysis from position: 87
2 jumps found. (Code = 44) Position 1 = 89, Position 2 = 158
Branch analysis from position: 89
2 jumps found. (Code = 44) Position 1 = 91, Position 2 = 163
Branch analysis from position: 91
2 jumps found. (Code = 44) Position 1 = 93, Position 2 = 168
Branch analysis from position: 93
2 jumps found. (Code = 44) Position 1 = 95, Position 2 = 173
Branch analysis from position: 95
2 jumps found. (Code = 44) Position 1 = 97, Position 2 = 178
Branch analysis from position: 97
1 jumps found. (Code = 42) Position 1 = 183
Branch analysis from position: 183
Branch analysis from position: 178
Branch analysis from position: 173
Branch analysis from position: 168
Branch analysis from position: 163
Branch analysis from position: 158
Branch analysis from position: 128
Branch analysis from position: 98
Branch analysis from position: 183
Branch analysis from position: 183
Branch analysis from position: 62
Branch analysis from position: 38
Branch analysis from position: 26
Branch analysis from position: 38
Branch analysis from position: 38
filename:       /in/9go2v
function name:  ip_info
number of ops:  185
compiled vars:  !0 = $ip, !1 = $purpose, !2 = $deep_detect, !3 = $output, !4 = $support, !5 = $continents, !6 = $ipdat, !7 = $address
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV_INIT                                        !0      null
          1        RECV_INIT                                        !1      'location'
          2        RECV_INIT                                        !2      <true>
    3     3        ASSIGN                                                   !3, null
    4     4        INIT_FCALL                                               'filter_var'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 275
          7        DO_ICALL                                         $9      
          8        TYPE_CHECK                                    4          $9
          9      > JMPZ                                                     ~10, ->38
    5    10    >   FETCH_R                      global              ~11     '_SERVER'
         11        FETCH_DIM_R                                      ~12     ~11, 'REMOTE_ADDR'
         12        ASSIGN                                                   !0, ~12
    6    13      > JMPZ                                                     !2, ->38
    7    14    >   INIT_FCALL                                               'filter_var'
         15        BEGIN_SILENCE                                    ~14     
         16        FETCH_R                      global              ~15     '_SERVER'
         17        FETCH_DIM_R                                      ~16     ~15, 'HTTP_X_FORWARDED_FOR'
         18        END_SILENCE                                              ~14
         19        SEND_VAL                                                 ~16
         20        SEND_VAL                                                 275
         21        DO_ICALL                                         $17     
         22      > JMPZ                                                     $17, ->26
    8    23    >   FETCH_R                      global              ~18     '_SERVER'
         24        FETCH_DIM_R                                      ~19     ~18, 'HTTP_X_FORWARDED_FOR'
         25        ASSIGN                                                   !0, ~19
    9    26    >   INIT_FCALL                                               'filter_var'
         27        BEGIN_SILENCE                                    ~21     
         28        FETCH_R                      global              ~22     '_SERVER'
         29        FETCH_DIM_R                                      ~23     ~22, 'HTTP_CLIENT_IP'
         30        END_SILENCE                                              ~21
         31        SEND_VAL                                                 ~23
         32        SEND_VAL                                                 275
         33        DO_ICALL                                         $24     
         34      > JMPZ                                                     $24, ->38
   10    35    >   FETCH_R                      global              ~25     '_SERVER'
         36        FETCH_DIM_R                                      ~26     ~25, 'HTTP_CLIENT_IP'
         37        ASSIGN                                                   !0, ~26
   13    38    >   INIT_FCALL                                               'str_replace'
         39        SEND_VAL                                                 <array>
         40        SEND_VAL                                                 null
         41        INIT_FCALL                                               'strtolower'
         42        INIT_FCALL                                               'trim'
         43        SEND_VAR                                                 !1
         44        DO_ICALL                                         $28     
         45        SEND_VAR                                                 $28
         46        DO_ICALL                                         $29     
         47        SEND_VAR                                                 $29
         48        DO_ICALL                                         $30     
         49        ASSIGN                                                   !1, $30
   14    50        ASSIGN                                                   !4, <array>
   15    51        ASSIGN                                                   !5, <array>
   24    52        INIT_FCALL                                               'filter_var'
         53        SEND_VAR                                                 !0
         54        SEND_VAL                                                 275
         55        DO_ICALL                                         $34     
         56      > JMPZ_EX                                          ~35     $34, ->62
         57    >   INIT_FCALL                                               'in_array'
         58        SEND_VAR                                                 !1
         59        SEND_VAR                                                 !4
         60        DO_ICALL                                         $36     
         61        BOOL                                             ~35     $36
         62    > > JMPZ                                                     ~35, ->183
   25    63    >   BEGIN_SILENCE                                    ~37     
         64        INIT_FCALL                                               'json_decode'
         65        INIT_FCALL                                               'file_get_contents'
         66        CONCAT                                           ~38     'http%3A%2F%2Fwww.geoplugin.net%2Fjson.gp%3Fip%3D', !0
         67        SEND_VAL                                                 ~38
         68        DO_ICALL                                         $39     
         69        SEND_VAR                                                 $39
         70        DO_ICALL                                         $40     
         71        END_SILENCE                                              ~37
         72        ASSIGN                                                   !6, $40
   26    73        BEGIN_SILENCE                                    ~42     
         74        INIT_FCALL                                               'trim'
         75        FETCH_OBJ_R                                      ~43     !6, 'geoplugin_countryCode'
         76        SEND_VAL                                                 ~43
         77        DO_ICALL                                         $44     
         78        STRLEN                                           ~45     $44
         79        END_SILENCE                                              ~42
         80        IS_EQUAL                                                 ~45, 2
         81      > JMPZ                                                     ~46, ->183
   27    82    > > SWITCH_STRING                                            !1, [ 'location':->98, 'address':->128, 'city':->158, 'state':->163, 'region':->168, 'country':->173, 'countrycode':->178, ], ->183
   28    83    >   IS_EQUAL                                                 !1, 'location'
         84      > JMPNZ                                                    ~47, ->98
   38    85    >   IS_EQUAL                                                 !1, 'address'
         86      > JMPNZ                                                    ~47, ->128
   46    87    >   IS_EQUAL                                                 !1, 'city'
         88      > JMPNZ                                                    ~47, ->158
   49    89    >   IS_EQUAL                                                 !1, 'state'
         90      > JMPNZ                                                    ~47, ->163
   52    91    >   IS_EQUAL                                                 !1, 'region'
         92      > JMPNZ                                                    ~47, ->168
   55    93    >   IS_EQUAL                                                 !1, 'country'
         94      > JMPNZ                                                    ~47, ->173
   58    95    >   IS_EQUAL                                                 !1, 'countrycode'
         96      > JMPNZ                                                    ~47, ->178
         97    > > JMP                                                      ->183
   30    98    >   BEGIN_SILENCE                                    ~48     
         99        FETCH_OBJ_R                                      ~49     !6, 'geoplugin_city'
        100        END_SILENCE                                              ~48
        101        INIT_ARRAY                                       ~50     ~49, 'city'
   31   102        BEGIN_SILENCE                                    ~51     
        103        FETCH_OBJ_R                                      ~52     !6, 'geoplugin_regionName'
        104        END_SILENCE                                              ~51
        105        ADD_ARRAY_ELEMENT                                ~50     ~52, 'state'
   32   106        BEGIN_SILENCE                                    ~53     
        107        FETCH_OBJ_R                                      ~54     !6, 'geoplugin_countryName'
        108        END_SILENCE                                              ~53
        109        ADD_ARRAY_ELEMENT                                ~50     ~54, 'country'
   33   110        BEGIN_SILENCE                                    ~55     
        111        FETCH_OBJ_R                                      ~56     !6, 'geoplugin_countryCode'
        112        END_SILENCE                                              ~55
        113        ADD_ARRAY_ELEMENT                                ~50     ~56, 'country_code'
   34   114        BEGIN_SILENCE                                    ~57     
        115        INIT_FCALL                                               'strtoupper'
        116        FETCH_OBJ_R                                      ~58     !6, 'geoplugin_continentCode'
        117        SEND_VAL                                                 ~58
        118        DO_ICALL                                         $59     
        119        FETCH_DIM_R                                      ~60     !5, $59
        120        END_SILENCE                                              ~57
        121        ADD_ARRAY_ELEMENT                                ~50     ~60, 'continent'
   35   122        BEGIN_SILENCE                                    ~61     
        123        FETCH_OBJ_R                                      ~62     !6, 'geoplugin_continentCode'
        124        END_SILENCE                                              ~61
        125        ADD_ARRAY_ELEMENT                                ~50     ~62, 'continent_code'
   29   126        ASSIGN                                                   !3, ~50
   37   127      > JMP                                                      ->183
   39   128    >   FETCH_OBJ_R                                      ~64     !6, 'geoplugin_countryName'
        129        INIT_ARRAY                                       ~65     ~64
        130        ASSIGN                                                   !7, ~65
   40   131        BEGIN_SILENCE                                    ~67     
        132        FETCH_OBJ_R                                      ~68     !6, 'geoplugin_regionName'
        133        STRLEN                                           ~69     ~68
        134        END_SILENCE                                              ~67
        135        IS_SMALLER_OR_EQUAL                                      1, ~69
        136      > JMPZ                                                     ~70, ->140
   41   137    >   FETCH_OBJ_R                                      ~72     !6, 'geoplugin_regionName'
        138        ASSIGN_DIM                                               !7
        139        OP_DATA                                                  ~72
   42   140    >   BEGIN_SILENCE                                    ~73     
        141        FETCH_OBJ_R                                      ~74     !6, 'geoplugin_city'
        142        STRLEN                                           ~75     ~74
        143        END_SILENCE                                              ~73
        144        IS_SMALLER_OR_EQUAL                                      1, ~75
        145      > JMPZ                                                     ~76, ->149
   43   146    >   FETCH_OBJ_R                                      ~78     !6, 'geoplugin_city'
        147        ASSIGN_DIM                                               !7
        148        OP_DATA                                                  ~78
   44   149    >   INIT_FCALL                                               'implode'
        150        SEND_VAL                                                 '%2C+'
        151        INIT_FCALL                                               'array_reverse'
        152        SEND_VAR                                                 !7
        153        DO_ICALL                                         $79     
        154        SEND_VAR                                                 $79
        155        DO_ICALL                                         $80     
        156        ASSIGN                                                   !3, $80
   45   157      > JMP                                                      ->183
   47   158    >   BEGIN_SILENCE                                    ~82     
        159        FETCH_OBJ_R                                      ~83     !6, 'geoplugin_city'
        160        END_SILENCE                                              ~82
        161        ASSIGN                                                   !3, ~83
   48   162      > JMP                                                      ->183
   50   163    >   BEGIN_SILENCE                                    ~85     
        164        FETCH_OBJ_R                                      ~86     !6, 'geoplugin_regionName'
        165        END_SILENCE                                              ~85
        166        ASSIGN                                                   !3, ~86
   51   167      > JMP                                                      ->183
   53   168    >   BEGIN_SILENCE                                    ~88     
        169        FETCH_OBJ_R                                      ~89     !6, 'geoplugin_regionName'
        170        END_SILENCE                                              ~88
        171        ASSIGN                                                   !3, ~89
   54   172      > JMP                                                      ->183
   56   173    >   BEGIN_SILENCE                                    ~91     
        174        FETCH_OBJ_R                                      ~92     !6, 'geoplugin_countryName'
        175        END_SILENCE                                              ~91
        176        ASSIGN                                                   !3, ~92
   57   177      > JMP                                                      ->183
   59   178    >   BEGIN_SILENCE                                    ~94     
        179        FETCH_OBJ_R                                      ~95     !6, 'geoplugin_countryCode'
        180        END_SILENCE                                              ~94
        181        ASSIGN                                                   !3, ~95
   60   182      > JMP                                                      ->183
   64   183    > > RETURN                                                   !3
   65   184*     > RETURN                                                   null

End of function ip_info

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
173.7 ms | 1419 KiB | 34 Q