but I came across a web based API, that could
be very useful in certain situations.
A captcha - (login, designed to prevent automated spam
by offering a human readable image pattern which needs to
be keyed in for access).
This captcha API is made available with only a few lines of code.
I tried it, and it worked exactly as expected.
Here is the sample script:
<?
session_start();
// You need a unique string that identifies the user. The easiest way is to
// simply use the session ID. But because sending session IDs to other servers
// can be a security problem, we use only a part of the session ID here.
// This is still a quasi-unique string, so it works just as well.
$captcha_id = substr(session_id(), 0, 15); // first 15 characters of the session ID
?>
<html><head></head><body>
<img src="http://captchator.com/captcha/image/<?= $captcha_id ?>" />
<br />
Please enter the text from the picture:
<form action="test.php" method="post">
<input type="text" name="captcha_answer" />
<input type="submit" name="submit" value="Check" />
</form>
<?
if ($_POST['captcha_answer']) {
// remove anything except letters and numbers (security)
$answer = preg_replace('/[^a-z0-9]+/i', '', $_POST['captcha_answer']);
// check answer
// if you get an error message because your provider has diabled allow_url_fopen,
// please use the myfile() function from the following website instead of file():
// http://www.klamm.de/crashforum/showpost.php?p=1041750&postcount=5
if (implode(file("http://captchator.com/captcha/check_answer/".$captcha_id."/".$answer)) == '1') {
echo '<div style="color: green">Answer correct!</div>';
} else {
echo '<div style="color: red">Wrong answer, please try again.</div>';
}
}
?>
<p>
See the <a href="test.php.txt">source code</a> of this script.
</p>
</body></html>
Here is the sample script loaded:

This is after I entered the proper code:

This is after I entered an improper code:

No difficult code here, just a simple API which is easily incorporated.
Not for everyone, but in the right situation, it could be very helpful
in the never ending fight against spam prevention.
References:
Captchator - Captcha service for PHP, Ruby on Rails, Python, ...


Sign In
Create Account


Back to top










