I can't seem to find the problem.
// Check that someone from this IP didn't register a user within the last hour (DoS prevention)
$query = mysqli_query($dbc, "SELECT COUNT(id) FROM accounts WHERE registration_ip = '".$_SERVER['REMOTE_ADDR']."' AND registered > ".(time() - 3600));
if (mysqli_num_rows($query) > 0) {
$errors[] = 'To prevent registration flooding, at least an hour has to pass between registrations from the same IP. Sorry for the inconvenience.';
}
Why does this always return true no matter what? Even if the accounts table is empty.
如果我没记错的话,您的数据将始终为1行,表示计数值(因为您使用的是计数)。
Even there is 0 rows that match your condition, it'll simply return this.
+-----------+
| COUNT(id) |
+-----------+
| 0 |
+-----------+
Because you wanted the count
of rows. Its 0
. Hence there is one row .
Here is how you should handle it.
$row = mysqli_fetch_row($query));
$count = intval($row[0]);
mysqli_free_result($query);
if ($count > 0)
....
You are checking the returned rows not the value. So check like that
$row = mysqli_fetch_row($query));
$count = $row[0];
if ($count > 0)
{
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.