3v4l.org

run code in 300+ PHP versions simultaneously
<?php // --------------------------- DETECT CITY BY IP --------------------------- // function detect_city($ip) { $default = 'UNKNOWN'; if (!is_string($ip) || strlen($ip) < 1 || $ip == '127.0.0.1' || $ip == 'localhost') $ip = '8.8.8.8'; $curlopt_useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)'; $url = 'http://ipinfodb.com/ip_locator.php?ip=' . urlencode($ip); $ch = curl_init(); $curl_opt = array( CURLOPT_FOLLOWLOCATION => 1, CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_USERAGENT => $curlopt_useragent, CURLOPT_URL => $url, CURLOPT_TIMEOUT => 1, CURLOPT_REFERER => 'http://' . $_SERVER['HTTP_HOST'], ); curl_setopt_array($ch, $curl_opt); $content = curl_exec($ch); if (!is_null($curl_info)) { $curl_info = curl_getinfo($ch); } curl_close($ch); if ( preg_match('{<li>City : ([^<]*)</li>}i', $content, $regs) ) { $city = $regs[1]; } if ( preg_match('{<li>State/Province : ([^<]*)</li>}i', $content, $regs) ) { $state = $regs[1]; } if( $city!='' && $state!='' ){ $location = $city . ', ' . $state; return $location; }else{ return $default; } } $test = '87.224.117.53'; echo detect_city($test); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/PD6d5
function name:  (null)
number of ops:  6
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   ASSIGN                                                   !0, '87.224.117.53'
   54     1        INIT_FCALL                                               'detect_city'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
   56     5      > RETURN                                                   1

Function detect_city:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 47) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 58
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 69
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 75, Position 2 = 77
Branch analysis from position: 75
2 jumps found. (Code = 46) Position 1 = 79, Position 2 = 81
Branch analysis from position: 79
2 jumps found. (Code = 43) Position 1 = 82, Position 2 = 87
Branch analysis from position: 82
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 87
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 81
Branch analysis from position: 77
Branch analysis from position: 69
Branch analysis from position: 58
Branch analysis from position: 16
Branch analysis from position: 14
Branch analysis from position: 11
Branch analysis from position: 8
filename:       /in/PD6d5
function name:  detect_city
number of ops:  89
compiled vars:  !0 = $ip, !1 = $default, !2 = $curlopt_useragent, !3 = $url, !4 = $ch, !5 = $curl_opt, !6 = $content, !7 = $curl_info, !8 = $regs, !9 = $city, !10 = $state, !11 = $location
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1        ASSIGN                                                   !1, 'UNKNOWN'
    9     2        TYPE_CHECK                                   64  ~13     !0
          3        BOOL_NOT                                         ~14     ~13
          4      > JMPNZ_EX                                         ~14     ~14, ->8
          5    >   STRLEN                                           ~15     !0
          6        IS_SMALLER                                       ~16     ~15, 1
          7        BOOL                                             ~14     ~16
          8    > > JMPNZ_EX                                         ~14     ~14, ->11
          9    >   IS_EQUAL                                         ~17     !0, '127.0.0.1'
         10        BOOL                                             ~14     ~17
         11    > > JMPNZ_EX                                         ~14     ~14, ->14
         12    >   IS_EQUAL                                         ~18     !0, 'localhost'
         13        BOOL                                             ~14     ~18
         14    > > JMPZ                                                     ~14, ->16
   10    15    >   ASSIGN                                                   !0, '8.8.8.8'
   12    16    >   ASSIGN                                                   !2, 'Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+5.1%3B+en-US%3B+rv%3A1.9.2%29+Gecko%2F20100115+Firefox%2F3.6+%28.NET+CLR+3.5.30729%29'
   14    17        INIT_FCALL                                               'urlencode'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $21     
         20        CONCAT                                           ~22     'http%3A%2F%2Fipinfodb.com%2Fip_locator.php%3Fip%3D', $21
         21        ASSIGN                                                   !3, ~22
   15    22        INIT_FCALL_BY_NAME                                       'curl_init'
         23        DO_FCALL                                      0  $24     
         24        ASSIGN                                                   !4, $24
   18    25        FETCH_CONSTANT                                   ~26     'CURLOPT_FOLLOWLOCATION'
         26        INIT_ARRAY                                       ~27     1, ~26
   19    27        FETCH_CONSTANT                                   ~28     'CURLOPT_HEADER'
         28        ADD_ARRAY_ELEMENT                                ~27     0, ~28
   20    29        FETCH_CONSTANT                                   ~29     'CURLOPT_RETURNTRANSFER'
         30        ADD_ARRAY_ELEMENT                                ~27     1, ~29
   21    31        FETCH_CONSTANT                                   ~30     'CURLOPT_USERAGENT'
         32        ADD_ARRAY_ELEMENT                                ~27     !2, ~30
   22    33        FETCH_CONSTANT                                   ~31     'CURLOPT_URL'
         34        ADD_ARRAY_ELEMENT                                ~27     !3, ~31
   23    35        FETCH_CONSTANT                                   ~32     'CURLOPT_TIMEOUT'
         36        ADD_ARRAY_ELEMENT                                ~27     1, ~32
   24    37        FETCH_CONSTANT                                   ~33     'CURLOPT_REFERER'
         38        FETCH_R                      global              ~34     '_SERVER'
         39        FETCH_DIM_R                                      ~35     ~34, 'HTTP_HOST'
         40        CONCAT                                           ~36     'http%3A%2F%2F', ~35
         41        ADD_ARRAY_ELEMENT                                ~27     ~36, ~33
   17    42        ASSIGN                                                   !5, ~27
   27    43        INIT_FCALL_BY_NAME                                       'curl_setopt_array'
         44        SEND_VAR_EX                                              !4
         45        SEND_VAR_EX                                              !5
         46        DO_FCALL                                      0          
   29    47        INIT_FCALL_BY_NAME                                       'curl_exec'
         48        SEND_VAR_EX                                              !4
         49        DO_FCALL                                      0  $39     
         50        ASSIGN                                                   !6, $39
   31    51        TYPE_CHECK                                    2  ~41     !7
         52        BOOL_NOT                                         ~42     ~41
         53      > JMPZ                                                     ~42, ->58
   32    54    >   INIT_FCALL_BY_NAME                                       'curl_getinfo'
         55        SEND_VAR_EX                                              !4
         56        DO_FCALL                                      0  $43     
         57        ASSIGN                                                   !7, $43
   35    58    >   INIT_FCALL_BY_NAME                                       'curl_close'
         59        SEND_VAR_EX                                              !4
         60        DO_FCALL                                      0          
   37    61        INIT_FCALL                                               'preg_match'
         62        SEND_VAL                                                 '%7B%3Cli%3ECity+%3A+%28%5B%5E%3C%5D%2A%29%3C%2Fli%3E%7Di'
         63        SEND_VAR                                                 !6
         64        SEND_REF                                                 !8
         65        DO_ICALL                                         $46     
         66      > JMPZ                                                     $46, ->69
   38    67    >   FETCH_DIM_R                                      ~47     !8, 1
         68        ASSIGN                                                   !9, ~47
   40    69    >   INIT_FCALL                                               'preg_match'
         70        SEND_VAL                                                 '%7B%3Cli%3EState%2FProvince+%3A+%28%5B%5E%3C%5D%2A%29%3C%2Fli%3E%7Di'
         71        SEND_VAR                                                 !6
         72        SEND_REF                                                 !8
         73        DO_ICALL                                         $49     
         74      > JMPZ                                                     $49, ->77
   41    75    >   FETCH_DIM_R                                      ~50     !8, 1
         76        ASSIGN                                                   !10, ~50
   44    77    >   IS_NOT_EQUAL                                     ~52     !9, ''
         78      > JMPZ_EX                                          ~52     ~52, ->81
         79    >   IS_NOT_EQUAL                                     ~53     !10, ''
         80        BOOL                                             ~52     ~53
         81    > > JMPZ                                                     ~52, ->87
   45    82    >   CONCAT                                           ~54     !9, '%2C+'
         83        CONCAT                                           ~55     ~54, !10
         84        ASSIGN                                                   !11, ~55
   46    85      > RETURN                                                   !11
         86*       JMP                                                      ->88
   48    87    > > RETURN                                                   !1
   51    88*     > RETURN                                                   null

End of function detect_city

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.34 ms | 1407 KiB | 18 Q