Is it best to use session variables or IP checks to prevent multiple votes in PHP scripts?

To prevent multiple votes in PHP scripts, it is generally best to use session variables rather than IP checks. Session variables are more reliable as they are tied to individual users rather than IP addresses which can change or be shared among multiple users. By storing a flag in the session once a user has voted, you can easily check and prevent them from voting multiple times.

session_start();

if(isset($_SESSION['voted'])) {
    echo "You have already voted.";
    // additional logic to handle multiple votes
} else {
    // process the vote
    $_SESSION['voted'] = true;
    echo "Thank you for voting!";
}