PHP

Quick PHP Captcha



Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Having Captcha these days is very necessary.  This blog will show you how to create a PHP Captcha image with SESSION authentication for forms. It looks much like Google or YouTube, and is way easier to read than some of the other Captcha scripts out there. Lets get started with a html form. Download the captcha.php file and include it as your img src.

Create the HTML Form

1
2
3
4
5
6
7
8
9
<form action="reg.php" method="post">
<strong>Name</strong> <input type="text" name="name" /> 
<strong>Message</strong> 
<textarea name="message"></textarea> 
<img id="captcha" src="captcha.php" alt="" /> 
<a id="change-image" onclick=" document.getElementById('captcha').src='captcha.php?'+Math.random(); document.getElementById('captcha-form').focus();" href="#">Not readable? Change text.</a></form>
<strong>Human Test</strong>
<input id="captcha-form" type="text" name="captcha" /> 
<input type="submit" />

Create the Form Action PHP File

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
session_start();
if (!empty($_REQUEST['captcha'])) 
{
 
if (empty($_SESSION['captcha']) || trim(strtolower($_REQUEST['captcha'])) != $_SESSION['captcha']) 
{
$note= 'Please enter correct text code';
} else {
 
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$name=htmlentities($_POST['name']); 
$message=htmlentities($_POST['message']);
// Insert SQL Statement 
$note= 'Values Inserted Successfully';
}
 
}
unset($_SESSION['captcha']);
}
?>

You can even have a configured word list and change settings all thanks to Cool-PHP-Captcha


View Comments
There are currently no comments.