ScrapeBox Forum
Simple Captcha : Form Validation with AJAX - Printable Version

+- ScrapeBox Forum (https://www.scrapeboxforum.com)
+-- Forum: Proxies, Pinging, Captcha Talk & ScrapeBox Blog Platforms (https://www.scrapeboxforum.com/Forum-proxies-pinging-captcha-talk-scrapebox-blog-platforms)
+--- Forum: ScrapeBox Captcha (https://www.scrapeboxforum.com/Forum-scrapebox-captcha)
+--- Thread: Simple Captcha : Form Validation with AJAX (/Thread-simple-captcha-form-validation-with-ajax)



Simple Captcha : Form Validation with AJAX - nilesh3240 - 01-21-2011




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:

<?php
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;
?>

Explaination:

* 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) {
xmlHttp=GetXmlHttpObject();
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 = '';
document.getElementById('code').focus();
return false;
}else{
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:

<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"


<head>
<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;}
</style>
</head>
<body>
<div id="result"></div>
<div id="form-captcha">
<form>
<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>
</form>
</div>
</body>
</html>


Under Creative Commons License: Attribution




RE: Simple Captcha : Form Validation with AJAX - googlealchemist - 02-06-2011

can someone put this in english plz?something practical...is this for automated captcha solving or was this just a bs post to get his backlink?


RE: Simple Captcha : Form Validation with AJAX - rustyfelix - 11-04-2011

Does the captcha's visibility in the login form effected or is visible and not because of the proxy servers?