How can PHP developers prevent Doppelpostings or duplicate posts in a forum setting?

Doppelpostings or duplicate posts in a forum setting can be prevented by implementing a check to see if the same post content has already been submitted by the user. This can be done by storing a hash of the post content in a session variable and comparing it with the hash of the new post content before allowing it to be submitted.

session_start();

if(isset($_POST['post_content'])){
    $post_content = $_POST['post_content'];
    $post_hash = md5($post_content);

    if($_SESSION['last_post_hash'] != $post_hash){
        // Process and save the new post
        $_SESSION['last_post_hash'] = $post_hash;
    } else {
        echo "Duplicate post detected. Please try again.";
    }
}