The condition for the number of invalid login attempts. Why does the IF condition work in Denver and does ELSE work on the server? In Denver, the number of attempts increases and a new entry with the same IP is added to the server.

$result = mysqli_query($db, "SELECT * FROM users WHERE login='$login' AND password='$password' AND activation='1'"); $myrow = mysqli_fetch_array($result); if (empty($myrow['id'])) { $select = mysqli_query($db, "SELECT ip FROM oshibka WHERE ip='$ip'"); $tmp = mysqli_fetch_row ($select); if ($ip == $tmp[0]) { $result52 = mysqli_query($db, "SELECT col FROM oshibka WHERE ip='$ip'"); $myrow52 = mysqli_fetch_array($result52); $col = $myrow52[0] + 1; mysqli_query ($db, "UPDATE oshibka SET col=$col,date=NOW() WHERE ip='$ip'"); } else { mysqli_query ($db, "INSERT INTO oshibka (ip,date,col) VALUES ('$ip',NOW(),'1')"); } 

In Denver ip 127.0.0.1, on the server 178.168.244. Is ip clipped? 4 values ​​should be?

Fields prntscr.com/bdu7zr on the server, in denver exactly the same

  • variable $ip , where does it come from in your code? -
  • @MasterAlex $ ip = getenv ("HTTP_X_FORWARDED_FOR"); if (empty ($ ip) || $ ip == 'unknown') {$ ip = getenv ("REMOTE_ADDR"); } - Eugene
  • Does this happen even if the table is empty initially on LAN? - MasterAlex
  • @masterAlex At first it was empty, and just added new entries - Eugene
  • That is, on LAN, this happens: in an empty table, a record is created first, and then +1 is added to it at each new entry? - MasterAlex

1 answer 1

I made a collective response from the comments, it seems everything wrote correctly:

The base for the ip field is varchar(12) , so when adding data from the local computer, IP 127.0.0.1 added and this is 9 characters, then everything is fine, everything works.

And on the server, the IP has increased, for example, 178.168.244.38 and when added to the database, it is truncated to 178.168.244. . Then this value is compared with 178.168.244.38 false and adds a new line, which is also truncated.