How can PHP be used to prevent multiple votes in online polls or surveys?
To prevent multiple votes in online polls or surveys using PHP, you can implement a system that tracks user votes using cookies or IP addresses. When a user submits a vote, check if their cookie or IP address has already voted. If it has, do not count the new vote.
// Check if user has already voted using cookies
if(isset($_COOKIE['voted'])) {
echo "You have already voted.";
} else {
// Process the vote
setcookie('voted', '1', time() + (86400 * 30)); // Set a cookie to prevent multiple votes
// Code to save the user's vote to the database
}