What are some alternative methods to prevent spam bots from submitting forms in PHP?
Spam bots can be prevented from submitting forms in PHP by implementing methods such as CAPTCHA, honeypot fields, and form token validation. These methods help to distinguish between human users and automated bots, reducing the likelihood of spam submissions.
// Implementing CAPTCHA in PHP form
<form action="submit.php" method="post">
<input type="text" name="name" placeholder="Name">
<input type="email" name="email" placeholder="Email">
<textarea name="message" placeholder="Message"></textarea>
<div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY"></div>
<input type="submit" value="Submit">
</form>
Keywords
Related Questions
- How can beginners ensure that their PHP scripts are correctly saved and interpreted by the server, especially when using basic text editors like Notepad?
- What are some common pitfalls when using PHP and MySQL together, especially when trying to link tables?
- How can the use of "for" loops in PHP code impact the retrieval of data from a database?