How do I exclude an IP range of writing in the mysql visitors database in PHP?

I have a problem, I have to exclude the IP Range of accounting visitors mysql database, and I have this code that works well:

<?php
// time
$temps = 60*24*3600;
// send
setcookie ("ip", "Visitor", time() + $temps);
// receive
$cookie_value = "Visitor";  
setcookie("ip", $cookie_value, time()+3600, "/cookies/", "exemple.com", 1, 1);  
ob_start();
date_default_timezone_set('Europe/Paris');
$date=date("Y-m-d H:i:s");
	

$servername = "host";
$username = "user";
$password = "password";
$dbname = "database";

$cookie=$_COOKIE['ip'];
$ip=$_SERVER['REMOTE_ADDR'];
$port=$_SERVER['REMOTE_PORT'];

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "INSERT INTO database ( date, ip, port, cookie)
VALUES ('$date', '$ip', '$port' , '$cookie')";

if (mysqli_query($conn, $sql)) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}

mysqli_close($conn);

ob_end_clean();
?>

How do I exclude IP Range writing ?

Any help will be truly appreciated.

Thank you.


Source: mysql

Leave a Reply