What are some best practices for implementing a voting system in PHP to avoid security vulnerabilities?

One common security vulnerability in a PHP voting system is allowing multiple votes from the same user. To prevent this, you can implement a session-based approach where each user is only allowed to vote once per session.

session_start();

if(isset($_SESSION['voted'])) {
    echo "You have already voted.";
} else {
    // Process the vote
    $_SESSION['voted'] = true;
}