I have on my PHP file a function that check if an IP is banned or not. For some reason my site is very slow and the problem is when I check if the IP is banned or not.
(I remove the code that checks and my site was fast again)
Here's my code:
// index.php - everything redirects to this file in the .htaccess
<?php
include('config.php');
if(isIpBanned($_SERVER['REMOTE_ADDR'])) {
die('access denied');
}
// rest of the code
here's my function
// config.php
<?php
function isIpBanned($db, $ip) { // $db is declared correctly
$goodIP = $db->getRecord("SELECT is_banned FROM security.ip WHERE ip = '$ip'"); // this function works and return 1 or 0
return (bool)$goodIP;
}
This query takes about 2 seconds to 3 seconds to run. Why? I don't have left join or other tables.
Thanks
IP
columnINT UNSIGNED
, an ipv6 in 2 BIGINT UNSIGNED
): this will make your tables smaller, and will require less I/O during scansand, as a side note, even if $_SERVER["REMOTE_ADDR"]
should be safe, NEVER FORGET TO ESCAPE THE DATA IN SQL QUERIES!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With