In what ways can the lack of IP-sperre functionality in a visitor counter script affect the accuracy of tracking unique visitors to a website?

The lack of IP-sperre functionality in a visitor counter script can affect the accuracy of tracking unique visitors to a website because multiple visitors from the same IP address will be counted as one unique visitor. To solve this issue, we can implement IP-sperre functionality in the script to filter out duplicate visitors based on their IP addresses.

// Get the visitor's IP address
$visitor_ip = $_SERVER['REMOTE_ADDR'];

// Check if the visitor's IP address is already in the database
$existing_visitor = $pdo->prepare("SELECT * FROM visitors WHERE ip_address = :ip_address");
$existing_visitor->bindParam(':ip_address', $visitor_ip);
$existing_visitor->execute();

// If the visitor's IP address is not in the database, add it
if($existing_visitor->rowCount() == 0) {
    $add_visitor = $pdo->prepare("INSERT INTO visitors (ip_address) VALUES (:ip_address)");
    $add_visitor->bindParam(':ip_address', $visitor_ip);
    $add_visitor->execute();
}