estoy creando un panel en el cual se insertarán las ips, user_Agent entre otros datos (como el fraud_rate) que ipqualityscore vea maliciosas, para así crear páginas libres de bots maliciosos. He creado la base de datos, los campos funcionan y demás pero no sé como podría hacer que el panel esté en constante actualización. Dejo aquí el code de mis webpages. Gracias Cabe recalcar que soy nuevo en mysqli por lo que si veis alguna barbaridad no os paséis demasiado conmigo jeje
Código página principal (html y pocas líneas de php)
<?php
$servername = "127.0.0.1"; // Host
$username = "root"; //User
$password = ''; // Password
$dbname = "prueba"; // dbname
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Conexion Fallida: " . $conn->connect_error);
}
$connp = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// Realizar una consulta MySQL
?>
<html>
<head>
<meta charset="UTF-8">
<title> Prueba de IpQuality </title>
</head>
<body>
<form class="dope" method="POST" action="php/app.php">
<div id="root">
<label for="submit">
Haga click aquí
</label>
<input type="submit" name="submit" placeholder="Click" id="Submit">
</form>
</div>
<div class="user">
<?php foreach ($conn->query('SELECT user_agent from drol') as $row){ ?>
<tr>
<td><?php echo $row['user_agent'] ?></td>
</tr>
<?php
}
?>
</body>
</html>
Código de IpQualityScore para obtener los datos (PHP)
$key = '';
/*
* Retrieve the user's IP address.
* You could also pull this from another source such as a database.
*
*/
$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
// Retrieve additional (optional) data points which help us enhance fraud scores.
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$user_language = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
// Set the strictness for this query. (0 (least strict) - 3 (most strict))
$strictness = 1;
// You may want to allow public access points like coffee shops, schools, corporations, etc...
$allow_public_access_points = 'true';
// Reduce scoring penalties for mixed quality IP addresses shared by good and bad users.
$lighter_penalties = 'false';
// Create parameters array.
$parameters = array(
'user_agent' => $user_agent,
'user_language' => $user_language,
'strictness' => $strictness,
'allow_public_access_points' => $allow_public_access_points,
'lighter_penalties' => $lighter_penalties,
);
/* User & Transaction Scoring
* Score additional information from a user, order, or transaction for risk analysis
* Please see the documentation and example code to include this feature in your scoring:
* https://www.ipqualityscore.com/documentation/proxy-detection/transaction-scoring
* This feature requires a Premium plan or greater
*/
// Format Parameters
$formatted_parameters = http_build_query($parameters);
// Create API URL
$url = sprintf(
'https://www.ipqualityscore.com/api/json/ip/%s/%s?%s',
$key,
$ip,
$formatted_parameters
);
// Fetch The Result
$timeout = 5;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
$json = curl_exec($curl);
curl_close($curl);
// Decode the result into an array.
$result = json_decode($json, true);
$ip = isset($_SERVER['HTTP_CF_CONNECTING_IP']) ? $_SERVER['HTTP_CF_CONNECTING_IP'] : $_SERVER['REMOTE_ADDR'];
$tor = $result['is_crawler'];
$ASN = $result['ASN'];
$fraud = $result['fraud_score'];
$device_brand = $result['device_brand'];
$operating_system = $result['operating_system'];
$recent_abuse = $result['recent_abuse'];
$host = $result['host'];
//try
/*$result_parser = $conn->msqli_query($conn,$parser);
$obj = $result_parser->fetch_object();
$parser = $obj->id;
$pro = $result_parser->fetch_assoc();
$parser = $pro['id'];
*/
//CONDITIONALS FOR GETTING ASS OFF MY WEBSITE BITCH
if ($result['fraud_score'] >= 50) {
$_GRABAR_SQL = "INSERT INTO drol (user_agent,fraud_rate,ip) VALUES ('$user_agent', $fraud,'$ip' )";
mysqli_query($conn, $_GRABAR_SQL);
echo ("ERROR DESCRIPTION: " . mysqli_error($conn));
print 'Get off my website dumbass bot' ;
}