Google Like CAPTCHA with PHP.
Wall Script
Follow Me:
Tuesday, July 06, 2010

Google Like CAPTCHA with PHP.

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/&gt;
<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']);
}
?>

Source code taken from : Cool-php-captcha
Was this article helpful?
Thanks! Your feedback helps us to improve 9lessons.info


44 comments:

  1. So easy and so simple.
    "code is poetry"
    Thanks a lot for share

    ReplyDelete
  2. how far its security vise strong comparing with Recaptcha?

    ReplyDelete
  3. Hi Sri,

    very nice post :)

    you are so active writter :D

    ReplyDelete
  4. I love it! Thank you! Keep them comming!
    Can you make an example Youtube style Thumbs Up/Like script with ajax?

    ReplyDelete
  5. @Marius Patrascu

    Thank you. Sure..

    ReplyDelete
  6. If the CAPTCHA is submitted incorrectly the form text boxes should still keep their POST values.

    ReplyDelete
  7. Hello,
    I am unable to downlaod from Box.net always use a mirror like Mediafire too. Its free and too good

    Thanks

    ReplyDelete
  8. very coool scripts thanks for share you ease my life :)

    ReplyDelete
  9. Thanks for easing my coding life, thanks for sharing, cools script!

    ReplyDelete
  10. Can U please write in APC (Alt. php cache )

    ReplyDelete
  11. I 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

    ReplyDelete
  12. awesome tutorial, srinivas. Thanks for sharing

    ReplyDelete
  13. Why 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...

    ReplyDelete
  14. Excellent code again mate, have added you to our site:
    http://sitehelp.com.au/google-like-captcha-for-forms/

    Thumbs up :)

    ReplyDelete
  15. thank .... It's nice!

    ReplyDelete
  16. awesome job, keep it up :D

    ReplyDelete
  17. Hi srinivas i want a captcha for HTML page....is there any solution for this...through ajax

    ReplyDelete
  18. very nice and usable! Thank you!
    Can you make and save Ip address and word and time captcha create in Database?

    ReplyDelete
  19. Hey, nice script.

    I'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!

    ReplyDelete
  20. It works fine in my local system...captcha image is not displaying on live server.......

    ReplyDelete
  21. Check for directory permissions and also check for gd2 extension.

    ReplyDelete
  22. Hello everyone,

    must 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

    ReplyDelete
  23. That's code is good, but I have an essential questions:
    if 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!

    ReplyDelete
  24. Anyway 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.

    ReplyDelete
  25. In case anyone still need the transparency, it's posted here: http://code.google.com/p/cool-php-captcha/issues/detail?id=14

    ReplyDelete
  26. its good captcha.
    but 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.....

    ReplyDelete
  27. i 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

    ReplyDelete
  28. Why do you name it Google Captcha?

    ReplyDelete
  29. thanks for sharing

    ReplyDelete
  30. Ran 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.

    ReplyDelete
  31. Nice work boss. can u make an example facebook timeline style cover photo with drag system?

    ReplyDelete
  32. Nice work boss. can u make an example facebook timeline style cover photo with drag system?

    ReplyDelete

Make in India