andre 4 rokov pred
rodič
commit
4bd3fb4a5d
1 zmenil súbory, kde vykonal 16 pridanie a 8 odobranie
  1. 16 8
      index.php

+ 16 - 8
index.php

@@ -54,26 +54,34 @@ function islisted($ip,$db) {
     }
     return true;
 }
-function delist($ip,$db) {
-    if(!islisted($ip,$db)) {
-        return false;
-    }
-    $dbAction = $db->prepare("INSERT INTO delist (ip) VALUES (?) ON DUPLICATE KEY UPDATE count = count + 1");
-    $dbAction->bind_param('i',ip2long($ip));
-    $dbAction->execute();
+
+function delistCount($ip,$db) {
     $dbAction = $db->prepare("SELECT count FROM delist WHERE ip = ?");
     $dbAction->bind_param('i',ip2long($ip));
     $dbAction->execute();
     $dbAction->store_result();
     $dbAction->bind_result($count);
     $dbAction->fetch();
-    if ($count > 3){
+    return $count;
+}
+
+function delist($ip,$db) {
+    if(!islisted($ip,$db)) {
+        return false;
+    }
+    //check delisting count
+    if (delistCount($ip,$db) > 3){
         echo "Fatal: ". $ip . " delisted to often!\n";
         return false;
     }
+    //delist ip
     $dbAction = $db->prepare("DELETE FROM list WHERE ip = ?");
     $dbAction->bind_param('i',ip2long($ip));
     $dbAction->execute();
+    //update delist count
+    $dbAction = $db->prepare("INSERT INTO delist (ip) VALUES (?) ON DUPLICATE KEY UPDATE count = count + 1");
+    $dbAction->bind_param('i',ip2long($ip));
+    $dbAction->execute();
     return true;
 }
 switch($action) {