What are the limitations of using IP addresses for preventing multiple votes in PHP scripts?

Using IP addresses to prevent multiple votes in PHP scripts has limitations because multiple users can share the same IP address (e.g., in a corporate network or public Wi-Fi). This can lead to legitimate users being blocked from voting. To address this issue, you can use a combination of IP address and user cookies to track unique voters.

// Check if the user has already voted based on IP address and cookie
$ip = $_SERVER['REMOTE_ADDR'];
$cookie_name = 'voted';
if (!isset($_COOKIE[$cookie_name])) {
    // Allow the user to vote
    // Set a cookie to track that the user has voted
    setcookie($cookie_name, 1, time() + (86400 * 30), "/"); // Cookie valid for 30 days
} else {
    // User has already voted
    echo "You have already voted.";
}