How can PHP sessions be utilized to ensure each user can only vote once per day in an online polling system?

To ensure each user can only vote once per day in an online polling system, we can utilize PHP sessions to store the user's voting status. When a user votes, we can check if they have already voted today by checking the session data. If they have not voted yet, we can allow them to vote and update the session data to mark that they have voted today.

session_start();

// Check if user has already voted today
if(isset($_SESSION['voted_date']) && $_SESSION['voted_date'] == date('Y-m-d')) {
    echo "You have already voted today.";
} else {
    // Process the vote
    // Update the session data to mark that the user has voted today
    $_SESSION['voted_date'] = date('Y-m-d');
    echo "Thank you for voting!";
}