How can PHP developers prevent their code from being exploited for spamming purposes?
To prevent PHP code from being exploited for spamming purposes, developers should implement proper input validation and sanitization techniques to ensure that user input is not being used maliciously. Additionally, developers should use CAPTCHA or other anti-spam measures to prevent automated spamming.
// Example of input validation and sanitization
$user_input = $_POST['user_input'];
$clean_input = filter_var($user_input, FILTER_SANITIZE_STRING);
// Example of implementing CAPTCHA
if($_POST['captcha'] != $_SESSION['captcha']){
// Handle error, possibly redirect back to form with an error message
}