What role does storing IP addresses play in improving the reliability of PHP-based click counting systems?

Storing IP addresses in PHP-based click counting systems can help improve reliability by preventing multiple clicks from the same user being counted multiple times. By tracking IP addresses, the system can identify and filter out duplicate clicks, ensuring more accurate counting of unique clicks.

// Get the user's IP address
$user_ip = $_SERVER['REMOTE_ADDR'];

// Check if the IP address has already clicked within a certain timeframe
$click_timeframe = time() - 3600; // 1 hour timeframe
$query = "SELECT COUNT(*) FROM clicks WHERE ip_address = '$user_ip' AND click_timestamp > $click_timeframe";
$result = mysqli_query($connection, $query);
$row = mysqli_fetch_array($result);

if ($row[0] == 0) {
    // Insert new click into the database
    $insert_query = "INSERT INTO clicks (ip_address, click_timestamp) VALUES ('$user_ip', UNIX_TIMESTAMP())";
    mysqli_query($connection, $insert_query);
}