Are you looking for Google style CAPTCHA (Human verification code) script for PHP projects, Please take a look at this post. I want to explain how to implement cool-php-captcha script for forms. Use it and add security to your web projects.
Download Script Live Demo
form.php
Contains HTML code image source captcha.php. File available in download script.
<form method="post" action="reg.php">
<b>Name</b><br/>
<input type="text" name="name" /><br/>
<b>Message</b><br/>
<textarea name="message"></textarea><br/>
<img src="captcha.php" id="captcha" /><br/>
<a href="#" onclick="
document.getElementById('captcha').src='captcha.php?'+Math.random();
document.getElementById('captcha-form').focus();"
id="change-image">Not readable? Change text.</a><br/><br/>
<b>Human Test</b><br/>
<input type="text" name="captcha" id="captcha-form" /><br/>
<input type="submit" />
</form>
<b>Name</b><br/>
<input type="text" name="name" /><br/>
<b>Message</b><br/>
<textarea name="message"></textarea><br/>
<img src="captcha.php" id="captcha" /><br/>
<a href="#" onclick="
document.getElementById('captcha').src='captcha.php?'+Math.random();
document.getElementById('captcha-form').focus();"
id="change-image">Not readable? Change text.</a><br/><br/>
<b>Human Test</b><br/>
<input type="text" name="captcha" id="captcha-form" /><br/>
<input type="submit" />
</form>
reg.php
Contains PHP code
<?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']);
}
?>
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']);
}
?>
Source code taken from : Cool-php-captcha
So easy and so simple.
ReplyDelete"code is poetry"
Thanks a lot for share
how far its security vise strong comparing with Recaptcha?
ReplyDeleteHi Sri,
ReplyDeletevery nice post :)
you are so active writter :D
I love it! Thank you! Keep them comming!
ReplyDeleteCan you make an example Youtube style Thumbs Up/Like script with ajax?
really good work!
ReplyDelete@Marius Patrascu
ReplyDeleteThank you. Sure..
If the CAPTCHA is submitted incorrectly the form text boxes should still keep their POST values.
ReplyDeleteHello,
ReplyDeleteI am unable to downlaod from Box.net always use a mirror like Mediafire too. Its free and too good
Thanks
very coool scripts thanks for share you ease my life :)
ReplyDeleteThanks for easing my coding life, thanks for sharing, cools script!
ReplyDeleteCan U please write in APC (Alt. php cache )
ReplyDeleteThank you
ReplyDeleteI got an small problem, my image does not refresh when I click "Not readable? Change text." it just follows the # link... can you have an small look here http://video.zubeetube.com/video/ive3vXv-XRk/#sh_commenting
ReplyDeleteawesome tutorial, srinivas. Thanks for sharing
ReplyDeleteAwesome :D i am ♥ing it.
ReplyDeleteWhy does the browser is not displaying an image. In Safari for example it displays a "?" where the image should be. I can't figure out what I'm doing wrong...
ReplyDeleteExcellent code again mate, have added you to our site:
ReplyDeletehttp://sitehelp.com.au/google-like-captcha-for-forms/
Thumbs up :)
Thanks
ReplyDeletethank .... It's nice!
ReplyDeleteawesome job, keep it up :D
ReplyDeleteHi srinivas i want a captcha for HTML page....is there any solution for this...through ajax
ReplyDeletethANKS
ReplyDeletevery nice and usable! Thank you!
ReplyDeleteCan you make and save Ip address and word and time captcha create in Database?
Hey, nice script.
ReplyDeleteI'm having some issues with it. It's working awesomely on my laptop with xampp, but when I am uploading the site to my fatcow server, the $_SESSION['captcha'] variable is turning out empty.
Any pointers what needs to be tightened?
Thanks again for making such an awesome tool!
nice sharing! :D
ReplyDeleteIt works fine in my local system...captcha image is not displaying on live server.......
ReplyDeleteCheck for directory permissions and also check for gd2 extension.
ReplyDeleteHello everyone,
ReplyDeletemust say this lib is amazing, it creates really nice images,thank you author!
but I also have two questions :)
1) I somehow can't find the option of 'line through text'
2) I am really missing the transparent option :(
I was trying to implement it for few days here:
http://scrp.at/7951c08735cb289025fc7f6c04f750b8ff41a86a
It's 'probably' almost ready, but I can't figure out how to remove the red 'border' around the text :( It appears somewhere after 'WriteText' function, but I really can't figure out WHY....
Basically it's original captcha class, just search for 'if($this->transparent)' to see what is changed to enable transparency...
Example of transparent bg here: http://d.pr/B3M2 (green color comes from the background-color of html page)
Thanks and waiting for a reply
That's code is good, but I have an essential questions:
ReplyDeleteif a hacker knew that I got my code from this site, how is it possible for him/she to hack the words, especially that these words are coming from a fixed list!
nice script.. very simple..
ReplyDeleteAnyway that when the CAPTCHA form is blank that it also says "Please enter a correct value"? That would be helpful instead of it just looking like it sent the form through.
ReplyDeleteIn case anyone still need the transparency, it's posted here: http://code.google.com/p/cool-php-captcha/issues/detail?id=14
ReplyDeleteits good captcha.
ReplyDeletebut some problem with this its possible when i submit page and form value is deleted if captcha code is invalid.
i want when use type invalid code then form value is not to be reset on only captcha value will be reset.
so if u get it then reply me.....
It's OK
ReplyDeletei m not able to get the image in form ,i m using mozila firefox .what can be the problem .please reply me as soon as possible
ReplyDeleteWhy do you name it Google Captcha?
ReplyDeletevery nice
ReplyDeletethanks for sharing
ReplyDeleteRan across this script and it works just fine. I am having a problem, however, in getting it to work in an existing $_SESSION-enabled environment. That is, using a slightly more secure technique I establish a "custom" session name and then include code for all routines to join this session. Problem is, I cannot seem to make captcha.php play nice and use the already existing session. Changing the $captcha->session_var to equal my special session name does not work. Any help would be surely appreciated. Thanks.
ReplyDeleteNice work boss. can u make an example facebook timeline style cover photo with drag system?
ReplyDeleteNice work boss. can u make an example facebook timeline style cover photo with drag system?
ReplyDeletethanks for sharing :D
ReplyDeletewhy this not work on ssl??
ReplyDelete