What are some common methods to prevent spam in PHP forums?

Spam in PHP forums can be prevented by implementing captcha verification, using honeypot fields, enforcing user registration, and implementing content moderation filters.

// Captcha verification
if($_POST['captcha'] != $_SESSION['captcha']) {
    // Handle error
}

// Honeypot field
if(!empty($_POST['website'])) {
    // Handle error
}

// User registration
if(!isset($_SESSION['user_id'])) {
    // Redirect to registration page
}

// Content moderation filters
$blacklist = array('viagra', 'casino', 'free money');
foreach($blacklist as $word) {
    if(stripos($_POST['content'], $word) !== false) {
        // Handle error
    }
}