andre 4 years ago
parent
commit
82e791380f
1 changed files with 20 additions and 5 deletions
  1. 20 5
      index.php

+ 20 - 5
index.php

@@ -1,19 +1,34 @@
 <?php
 error_reporting(E_ALL);
 $ip = $_GET['ip'];
-
+$token = $_GET['token'];
 $db = new mysqli('localhost', 'ban', 'Blubb123-', 'ban');
 if ($db->connect_errno){
     die($db->connect_error);
 }
 $db->set_charset('utf8');
+
+function checkToken($token,$db) {
+    $dbAction = $db->prepare("SELECT FROM client WHERE token = ?");
+    $dbAction->bind_param('s',$token);
+    $dbAction->execute();
+    $dbAction->bind_result($token, $description);
+    echo "$description" . PHP_EOL;
+    if ($dbAction->num_rows == 1){
+        return true;
+    }
+    return false;
+}
+
 function set($ip,$db) {
     $dbAction = $db->prepare("INSERT INTO list (ip) VALUES (?) ON DUPLICATE KEY UPDATE count = count + 1");
     $dbAction->bind_param('i',$ip);
     return $dbAction->execute();
 }
-if(set(ip2long($ip),$db)){
-    echo "inserted $ip" . PHP_EOL;
-} else {
-    echo "fehler" . PHP_EOL;
+if (checkToken($token,$db)){
+    if(set(ip2long($ip),$db)){
+        echo "inserted $ip" . PHP_EOL;
+    } else {
+        echo "fehler" . PHP_EOL;
+    };
 };