3v4l.org

run code in 300+ PHP versions simultaneously
<?php // http://forrk.co.uk/blog/Finding-a-short-Twitter-Username-Mission-Impossible/1 function checkusername($username){ if(!empty($username) && $username != ''){ $url="http://twitter.com/".$username; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $return = curl_exec($ch); $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if($http_status == '404'){ echo 'Available: '.$username."\n"; } else{ // not available } }// if }// function checkusername($username) // http://stackoverflow.com/a/19067884/901502 function build_usernames($chars, $size, $combinations = array()){ // if it's the first iteration, the first set // of combinations is the same as the set of characters if(empty($combinations)){ $combinations = $chars; } // we're done if we're at size 1 if ($size == 1) { return $combinations; } // initialise array to put new values in $new_combinations = array(); // loop through existing combinations and character set to create strings foreach($combinations as $combination){ foreach($chars as $char){ $new_combinations[] = $combination . $char; }// foreach }// foreach // call same function again for the next iteration return build_usernames($chars, $size - 1, $new_combinations); }// function build_usernames($chars, $size, $combinations = array()) // set the possible chars to build the username from $possible_chars = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm'); // build the user name combinations for up to 4 char usernames $possible_usernames = build_usernames($possible_chars, 4); // loop through all usernames and check each with twitter foreach($possible_usernames as $username){ checkusername($username); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/ES1pT
function name:  (null)
number of ops:  14
compiled vars:  !0 = $possible_chars, !1 = $possible_usernames, !2 = $username
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   58     0  E >   ASSIGN                                                   !0, <array>
   61     1        INIT_FCALL                                               'build_usernames'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 4
          4        DO_FCALL                                      0  $4      
          5        ASSIGN                                                   !1, $4
   64     6      > FE_RESET_R                                       $6      !1, ->12
          7    > > FE_FETCH_R                                               $6, !2, ->12
   65     8    >   INIT_FCALL                                               'checkusername'
          9        SEND_VAR                                                 !2
         10        DO_FCALL                                      0          
   64    11      > JMP                                                      ->7
         12    >   FE_FREE                                                  $6
   66    13      > RETURN                                                   1

Function checkusername:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 61
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 61
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 61
Branch analysis from position: 61
Branch analysis from position: 6
filename:       /in/ES1pT
function name:  checkusername
number of ops:  62
compiled vars:  !0 = $username, !1 = $url, !2 = $ch, !3 = $return, !4 = $http_status
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    5     1        ISSET_ISEMPTY_CV                                 ~5      !0
          2        BOOL_NOT                                         ~6      ~5
          3      > JMPZ_EX                                          ~6      ~6, ->6
          4    >   IS_NOT_EQUAL                                     ~7      !0, ''
          5        BOOL                                             ~6      ~7
          6    > > JMPZ                                                     ~6, ->61
    7     7    >   CONCAT                                           ~8      'http%3A%2F%2Ftwitter.com%2F', !0
          8        ASSIGN                                                   !1, ~8
    9     9        INIT_FCALL_BY_NAME                                       'curl_init'
         10        DO_FCALL                                      0  $10     
         11        ASSIGN                                                   !2, $10
   10    12        INIT_FCALL_BY_NAME                                       'curl_setopt'
         13        SEND_VAR_EX                                              !2
         14        FETCH_CONSTANT                                   ~12     'CURLOPT_URL'
         15        SEND_VAL_EX                                              ~12
         16        SEND_VAR_EX                                              !1
         17        DO_FCALL                                      0          
   11    18        INIT_FCALL_BY_NAME                                       'curl_setopt'
         19        SEND_VAR_EX                                              !2
         20        FETCH_CONSTANT                                   ~14     'CURLOPT_FOLLOWLOCATION'
         21        SEND_VAL_EX                                              ~14
         22        SEND_VAL_EX                                              1
         23        DO_FCALL                                      0          
   12    24        INIT_FCALL_BY_NAME                                       'curl_setopt'
         25        SEND_VAR_EX                                              !2
         26        FETCH_CONSTANT                                   ~16     'CURLOPT_SSL_VERIFYHOST'
         27        SEND_VAL_EX                                              ~16
         28        SEND_VAL_EX                                              0
         29        DO_FCALL                                      0          
   13    30        INIT_FCALL_BY_NAME                                       'curl_setopt'
         31        SEND_VAR_EX                                              !2
         32        FETCH_CONSTANT                                   ~18     'CURLOPT_SSL_VERIFYPEER'
         33        SEND_VAL_EX                                              ~18
         34        SEND_VAL_EX                                              0
         35        DO_FCALL                                      0          
   14    36        INIT_FCALL_BY_NAME                                       'curl_setopt'
         37        SEND_VAR_EX                                              !2
         38        FETCH_CONSTANT                                   ~20     'CURLOPT_RETURNTRANSFER'
         39        SEND_VAL_EX                                              ~20
         40        SEND_VAL_EX                                              1
         41        DO_FCALL                                      0          
   15    42        INIT_FCALL_BY_NAME                                       'curl_exec'
         43        SEND_VAR_EX                                              !2
         44        DO_FCALL                                      0  $22     
         45        ASSIGN                                                   !3, $22
   16    46        INIT_FCALL_BY_NAME                                       'curl_getinfo'
         47        SEND_VAR_EX                                              !2
         48        FETCH_CONSTANT                                   ~24     'CURLINFO_HTTP_CODE'
         49        SEND_VAL_EX                                              ~24
         50        DO_FCALL                                      0  $25     
         51        ASSIGN                                                   !4, $25
   17    52        INIT_FCALL_BY_NAME                                       'curl_close'
         53        SEND_VAR_EX                                              !2
         54        DO_FCALL                                      0          
   19    55        IS_EQUAL                                                 !4, '404'
         56      > JMPZ                                                     ~28, ->61
   20    57    >   CONCAT                                           ~29     'Available%3A+', !0
         58        CONCAT                                           ~30     ~29, '%0A'
         59        ECHO                                                     ~30
         60      > JMP                                                      ->61
   26    61    > > RETURN                                                   null

End of function checkusername

Function build_usernames:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 9
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 20
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 18
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 18
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 6
filename:       /in/ES1pT
function name:  build_usernames
number of ops:  29
compiled vars:  !0 = $chars, !1 = $size, !2 = $combinations, !3 = $new_combinations, !4 = $combination, !5 = $char
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      <array>
   33     3        ISSET_ISEMPTY_CV                                         !2
          4      > JMPZ                                                     ~6, ->6
   34     5    >   ASSIGN                                                   !2, !0
   38     6    >   IS_EQUAL                                                 !1, 1
          7      > JMPZ                                                     ~8, ->9
   39     8    > > RETURN                                                   !2
   43     9    >   ASSIGN                                                   !3, <array>
   46    10      > FE_RESET_R                                       $10     !2, ->20
         11    > > FE_FETCH_R                                               $10, !4, ->20
   47    12    > > FE_RESET_R                                       $11     !0, ->18
         13    > > FE_FETCH_R                                               $11, !5, ->18
   48    14    >   CONCAT                                           ~13     !4, !5
         15        ASSIGN_DIM                                               !3
         16        OP_DATA                                                  ~13
   47    17      > JMP                                                      ->13
         18    >   FE_FREE                                                  $11
   46    19      > JMP                                                      ->11
         20    >   FE_FREE                                                  $10
   53    21        INIT_FCALL_BY_NAME                                       'build_usernames'
         22        SEND_VAR_EX                                              !0
         23        SUB                                              ~14     !1, 1
         24        SEND_VAL_EX                                              ~14
         25        SEND_VAR_EX                                              !3
         26        DO_FCALL                                      0  $15     
         27      > RETURN                                                   $15
   55    28*     > RETURN                                                   null

End of function build_usernames

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
169.09 ms | 1407 KiB | 15 Q