3v4l.org

run code in 300+ PHP versions simultaneously
<?php //************************************************************* // place $req_status any where it will show the button/msg etc //************************************************************* //$user_email = email@example.com // get id by matching email address $result = mysql_query("SELECT id FROM tbluser WHERE email = '$user_email'"); if (!$result) { echo 'Could not run query'; } $row = mysql_fetch_assoc($result); $user_id = $row['id']; // id of the user //logged in. I assumed that you have the user id and profile id as follows. //$_SESSION['user_id'] = $user_id; if($_GET['fid']){ // ---------------------------------------------------- $friend_id = $_GET['fid']; // profile user id. // it shows "Friends" if user is friend. or "Add friend" or "Request pending" $query1="SELECT * FROM friends WHERE (user_id = '$user_id' AND friend_id = '$friend_id') OR (friend_id = '$friend_id' AND user_id = '$user_id')"; $result = mysql_query($query1); $row = mysql_num_rows($result); if ($row == 1) { // exist, whether it's active or not while($row = mysql_fetch_assoc($result)) { if ($row['status'] == 1) { echo "Friends"; } elseif ($row['status'] == 0) { if($row['user_id'] == $user_id){ $req_status = "Request pending"; //echo "Request pending"; } elseif($user_id == $row['friend_id']) { $uid = $row["user_id"]; $req_status = '<a href="add_friend.php?fid=$uid">Accept request</a> or <a href="ignore_request.php?fid=$uid">Ignore</a>'; //echo "<a href='add_friend.php?fid=".$row['user_id']."'>Accept request</a> or <a } } else { if($row['user_id'] == $user_id){ $req_status = "Request pending"; //echo "Request pending"; } else { $req_status = '<a href="add_friend.php?fid='.$friend_id.'">Add Friend</a>'; //echo "<a href='add_friend.php?fid=".$friend_id."'>Add Friend</a>"; } } } } else { // if the relationship don't exist $req_status = '<a href="add_friend.php?fid='.$friend_id.'">Add friend</a>'; //echo "<a href='add_friend.php?fid=".$friend_id."'>Add friend</a>"; } // ---------------------------------------------------- } ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 80
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 42, Position 2 = 77
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 43
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 80
Branch analysis from position: 80
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 43
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 48
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 51, Position 2 = 63
Branch analysis from position: 51
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 56
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 62
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 62
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
Branch analysis from position: 62
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 68
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 71
Branch analysis from position: 71
Branch analysis from position: 68
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 43
Branch analysis from position: 76
Branch analysis from position: 43
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 80
Branch analysis from position: 10
filename:       /in/M8R3r
function name:  (null)
number of ops:  81
compiled vars:  !0 = $result, !1 = $user_email, !2 = $row, !3 = $user_id, !4 = $friend_id, !5 = $query1, !6 = $req_status, !7 = $uid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   INIT_FCALL_BY_NAME                                       'mysql_query'
          1        ROPE_INIT                                     3  ~9      'SELECT+id+FROM+tbluser+WHERE+email+%3D+%27'
          2        ROPE_ADD                                      1  ~9      ~9, !1
          3        ROPE_END                                      2  ~8      ~9, '%27'
          4        SEND_VAL_EX                                              ~8
          5        DO_FCALL                                      0  $11     
          6        ASSIGN                                                   !0, $11
   11     7        BOOL_NOT                                         ~13     !0
          8      > JMPZ                                                     ~13, ->10
   12     9    >   ECHO                                                     'Could+not+run+query'
   14    10    >   INIT_FCALL_BY_NAME                                       'mysql_fetch_assoc'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0  $14     
         13        ASSIGN                                                   !2, $14
   16    14        FETCH_DIM_R                                      ~16     !2, 'id'
         15        ASSIGN                                                   !3, ~16
   22    16        FETCH_R                      global              ~18     '_GET'
         17        FETCH_DIM_R                                      ~19     ~18, 'fid'
         18      > JMPZ                                                     ~19, ->80
   26    19    >   FETCH_R                      global              ~20     '_GET'
         20        FETCH_DIM_R                                      ~21     ~20, 'fid'
         21        ASSIGN                                                   !4, ~21
   30    22        ROPE_INIT                                     9  ~24     'SELECT+%2A+FROM+friends+WHERE+%28user_id+%3D+%27'
         23        ROPE_ADD                                      1  ~24     ~24, !3
         24        ROPE_ADD                                      2  ~24     ~24, '%27+AND+friend_id+%3D+%27'
         25        ROPE_ADD                                      3  ~24     ~24, !4
         26        ROPE_ADD                                      4  ~24     ~24, '%27%29+OR+%28friend_id+%3D+%27'
         27        ROPE_ADD                                      5  ~24     ~24, !4
         28        ROPE_ADD                                      6  ~24     ~24, '%27+AND+user_id+%3D+%0A%0A%27'
   32    29        ROPE_ADD                                      7  ~24     ~24, !3
         30        ROPE_END                                      8  ~23     ~24, '%27%29'
   30    31        ASSIGN                                                   !5, ~23
   34    32        INIT_FCALL_BY_NAME                                       'mysql_query'
         33        SEND_VAR_EX                                              !5
         34        DO_FCALL                                      0  $30     
         35        ASSIGN                                                   !0, $30
   36    36        INIT_FCALL_BY_NAME                                       'mysql_num_rows'
         37        SEND_VAR_EX                                              !0
         38        DO_FCALL                                      0  $32     
         39        ASSIGN                                                   !2, $32
   38    40        IS_EQUAL                                                 !2, 1
         41      > JMPZ                                                     ~34, ->77
   39    42    > > JMP                                                      ->71
   40    43    >   FETCH_DIM_R                                      ~35     !2, 'status'
         44        IS_EQUAL                                                 ~35, 1
         45      > JMPZ                                                     ~36, ->48
   41    46    >   ECHO                                                     'Friends'
         47      > JMP                                                      ->71
   42    48    >   FETCH_DIM_R                                      ~37     !2, 'status'
         49        IS_EQUAL                                                 ~37, 0
         50      > JMPZ                                                     ~38, ->63
   43    51    >   FETCH_DIM_R                                      ~39     !2, 'user_id'
         52        IS_EQUAL                                                 !3, ~39
         53      > JMPZ                                                     ~40, ->56
   44    54    >   ASSIGN                                                   !6, 'Request+pending'
         55      > JMP                                                      ->62
   46    56    >   FETCH_DIM_R                                      ~42     !2, 'friend_id'
         57        IS_EQUAL                                                 !3, ~42
         58      > JMPZ                                                     ~43, ->62
   47    59    >   FETCH_DIM_R                                      ~44     !2, 'user_id'
         60        ASSIGN                                                   !7, ~44
   48    61        ASSIGN                                                   !6, '%3Ca+href%3D%22add_friend.php%3Ffid%3D%24uid%22%3EAccept+request%3C%2Fa%3E+or+%3Ca+%0A%0Ahref%3D%22ignore_request.php%3Ffid%3D%24uid%22%3EIgnore%3C%2Fa%3E'
         62    > > JMP                                                      ->71
   55    63    >   FETCH_DIM_R                                      ~47     !2, 'user_id'
         64        IS_EQUAL                                                 !3, ~47
         65      > JMPZ                                                     ~48, ->68
   56    66    >   ASSIGN                                                   !6, 'Request+pending'
         67      > JMP                                                      ->71
   59    68    >   CONCAT                                           ~50     '%3Ca+href%3D%22add_friend.php%3Ffid%3D', !4
         69        CONCAT                                           ~51     ~50, '%22%3EAdd+Friend%3C%2Fa%3E'
         70        ASSIGN                                                   !6, ~51
   39    71    >   INIT_FCALL_BY_NAME                                       'mysql_fetch_assoc'
         72        SEND_VAR_EX                                              !0
         73        DO_FCALL                                      0  $53     
         74        ASSIGN                                           ~54     !2, $53
         75      > JMPNZ                                                    ~54, ->43
         76    > > JMP                                                      ->80
   65    77    >   CONCAT                                           ~55     '%3Ca+href%3D%22add_friend.php%3Ffid%3D', !4
         78        CONCAT                                           ~56     ~55, '%22%3EAdd+friend%3C%2Fa%3E'
         79        ASSIGN                                                   !6, ~56
   73    80    > > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.23 ms | 1394 KiB | 13 Q