Visitors Today: 6
Total Visits: 456993


Do you have source code, articles, and tutorials to share?
Visual Basic, VB.NET, C#, PHP/MySQL, C/C++, Java/JavaScript, ASP/ASP.NET, MS Access, FoxPro, SQL
You can write your own content here.


    If the information on this site helps you and you would like to make donation to please click the LINK below.

    If you want to support us, please make a contribution. Any amount is appreciated. To make a donation via PayPal, credit card, or e-check..

    Please click the DONATE link..

    Your contribution will make grow in the future.



Captcha in PHP by google captcha with dynamic reload

    Posted GraniteGear Posted On October 20, 2014

    PHP 2 Current Comments 16987 Views

    Like 0 people liked this.

    Here is the simple google captcha with dynamic reload. Google give us many of its services for free with proper license. it also allows the captcha image for our website. Captcha is using for avoid Anti Spam users in websites. It is for avoiding spam comments in our blog or websites. How captcha will filter anti spam users means? For E.g you have a form with the fields of username, email, message with the action of POST with the action of `action.php` file. Any user can post the values or spam values without using your website or your form page in browser. Simply spammers will POST the values to your In this way the spam comments are posting to your blogs and websites. To avoid this we are using captcha to let know is that user is an human or not. Here is the simple captcha ready to integrate in your website which contains dynamic captcha reload without page reload.

    Copy paste the below code in your form where you want to avoid spammers:
    $msg = '';
    $original_captcha = $_SESSION["captcha"]; // session 'captcha' has been alreadey created in captcha.php file, if you want to rename the session open the captcha.php file and find and change the name of the session
    $user_captcha = $_POST["captcha"];
    if($user_captcha == $original_captcha){
    $msg = '<span class="success">Captcha Matched!</span>';
    $msg = '<span class="error">Oops! Captcha Mismatched!</span>';
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Simple captcha validation with dynamic captcha refresh</title>
    <script src="//"></script>
    <script type="text/javascript">
    $("#as_captcha").attr("src", "captcha.php?"+(new Date()).getTime()); // browser will save the captcha image in its cache so add '?some_unique_char' to set new URL for each click
    margin: 0;
    padding: 0;
    font-family: arial;
    color: #2C2C2C;
    font-size: 14px;
    h1 a{
    h1 a:hover{
    color: #069FDF;
    margin: 0 auto;
    width: 1000px;
    width: 700px;
    margin: 0 auto;
    border:2px dashed #17A3F7;
    padding: 20px;
    <div class="wrapper">
    <h1><a href="">Simple captcha with dynamic refresh</a></h1>
    <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
    <table class="mytable">
    <td colspan="2" align="center"><?php echo $msg; ?></td>
    <td valign="bottom">Enter the captcha</td>
    <td><img src="captcha.php" id="as_captcha" alt="Captcha" /></td>
    <td><input type="text" name="captcha" /></td>
    <td><a class="a" id="change_captcha">Can't read? try another one</a></td>
    <td><input type="submit" name="submit" value="Post It" /></td>

    You can the see the image source captcha.php, just download the file there you can get the complete source code which is ready to use. We have used jQuery here for dynamic captcha image change. If the user feels hard to read the captcha image means we need to allow them to change another capcha image by user friendly without reload the whole form or the whole page. Simply use the jQuery onClick() change the captcha image attr() like in this example.



Share With Your Friends

Fatal error: Uncaught Error: Call to undefined function mysql_escape_string() in /home/xtremgoo/laravel/public/comments/inc_rate.php:89 Stack trace: #0 /home/xtremgoo/laravel/public/pages/display.php(401): getComments('84', 'post') #1 /home/xtremgoo/laravel/public/body.php(18): include('/home/xtremgoo/...') #2 /home/xtremgoo/laravel/public/index.php(376): include('/home/xtremgoo/...') #3 {main} thrown in /home/xtremgoo/laravel/public/comments/inc_rate.php on line 89