<? Online-PHP::Tutorials ?>

« Back

  • CAPTCHA implementation

    Intro

    Integration of a relatively simple captcha in your site.
    There is an explanation on their site how to use it, I am going to show the complete required PHP code.



    Preface

    On their site there are two lines (two URLs) which we are going to use:
    1. Go to http://captchator.com/captcha/image/(anything you like) and read the text from the picture.
    2. Go to http://captchator.com/captcha/check_answer/(anything you like)/(text from the picture). If you entered the text correctly, you will see "1".



    Integration

    Within your form add an image and a simple text input
    the image:
    <img src="http://captchator.com/captcha/image/online-php.com" width="130" height="90" />
    * "online-php.com" is a unique string which you have to append to the URL
    the input (text)
    <input type="text" name="captcha">

    When you receive the request (POST) you check the CAPTCHA in the next way:
    if (file_get_contents('http://captchator.com/captcha/check_answer/online-php.com/'.urlencode($_POST['captcha'])) != '1') {
        header('Location: '.$_SERVER['HTTP_REFERER']);
        die();
    }
    * Same thing here - "online-php.com" is a unique string which you have to append to the URL

     

    * also: Google reCaptcha free service:

    http://code.google.com/apis/recaptcha/docs/php.html

     



    ENJOY