Generate Instant Copy Using AI. Claim your free 10,000 words

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Captcha : Form Validation with AJAX

Captcha validation or code that serves to avoid the spam. Spammers work automatically using comment spam engines to find the form or contact form or other forms on the web. Then they fill out the form with information on trash / not useful for most people or we often call it SPAM. To ban (cease-and desist) were created captcha spam attacks, a code manually inputted by the user to indicate that the user is not a spammer but a human.

There are so many types of captcha that has been created, ranging from simple to complete, and some even

complete with the sound (audio). But the problem is how captcha is working? Here, we discuss how a simple captcha work. Captcha code consists of numbers and letters, without the image. First, create a file named captcha.php, then type the code below:

session_start();$length = 5;
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$string = '';

for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
echo $string;

$_SESSION['code'] = $string;


* session_start () is a function to start the session, the session was used to store the code into the session.
* $length is the length of the code we want. You can specify a lot of characters you want.
* $characters are variable traits that would be in the show or who will be drawn at random codes (mt_rand).
* mt_rand functions are the functions randomize the characters in the variable $ characters.
* $_SESSION ['Code'] is a working session save $ string variable into session in progress (code).

The second step is to make the AJAX engine (validasi.js) for the validation code you submit. The following code:

var xmlHttp;
function GetXmlHttpObject() {
var xmlHttp=null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;

function validasi(actionstr) {
if (xmlHttp==null) {
alert ("Browser does not support HTTP Request")
return false;

var actionstr;
//addproducts param values list specification
if(actionstr == "checkCode"){
var inputCode = document.getElementById('code').value;
var captchaCode = document.getElementById('captcha').value;

if(inputCode != captchaCode){
alert('The code you entered is wrong, Please Try Again');
document.getElementById('code').style.background = 'red';
document.getElementById('code').value = '';
return false;
alert('Success !');
document.getElementById('result')[removed] = 'Success !';
document.getElementById('code').value = '';
document.getelementById('form-captcha').style.visibility = 'hidden';
document.getelementById('form-captcha').style.display = 'none';

The last step is the implementation of the captcha in index.php. Here's the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" type="text/javascript" src="validasi.js"></script>
<title>Simple Captcha - AJAX Validation</title>
<style type="text/css">
#hasil {background:#FFCC00; font-family:Georgia; font-size:24px; color:#000066;}
#form-captcha input.fields {width:250px; border:1px solid #0000FF;}
#form-captcha input.button {width:80px; border:1px solid #0000FF; background:#0066FF; color:#FFFFFF;}
#form-captcha input.button:hover {width:80px; border:1px solid #0000FF; background: #FF9900; color: #000000;}
<div id="result"></div>
<div id="form-captcha">
<p>Enter Code : <br />
<input type="text" name="code" id="code" class="fields" /></p>
<p><?php include("captcha.php"); ?></p>
<input type="hidden" name="captcha" id="captcha" value="<?php echo $_SESSION['code']; ?>" />
<p><input type="button" value="Validate !" onclick="[removed]validasi('checkCode')" class="button" /></p>

Under Creative Commons License: Attribution

can someone put this in english plz?something this for automated captcha solving or was this just a bs post to get his backlink?
Does the captcha's visibility in the login form effected or is visible and not because of the proxy servers?

Users browsing this thread: 1 Guest(s)