<<< To scripts      


Captcha Talk - Animated Talking Captcha php class


Captcha code Listen to the captcha
Captcha Code:  
Language: de Language: fr Language: nl Language: uk Language: us


A captcha is used to protect forms from non-human submission. A sound captcha allows visitors to listen to this captcha code. This class can be used to add audio to any session based php captcha or as a full working image captcha with a mp3 sound.

Added character mapping between languages ( to make automated audio recognition harder ).
It can use characters from other languages with the same sound also for audio generation.
Mp3 Image Captcha config options:
- Configurable size and character length.
- Set (random) background, shadow and font colors.
- Set (random) .ttf fonts.
- Set (random) background images.
- Validate a visitors IP against DNSBL ( IP blacklists - Optional ).
New options/changes:

- Template based Captcha html to easily adjust to your design
- Now also works with non javascript browsers
- XMLHTTP support for captcha language choice without page refresh
- Added a somewhat faster responding Javascript - Updated: Apr 2009.
( Since this js triggers the browser capability to play the mp3 code there is a little delay
in starting the captcha mp3 the first time )



See the source of the index.php in the download and the class file for the optional config of the Mp3 Image Captcha


<?php
/********************************************************************************
* MP3 captchaform - Put this at the top of your form php page
********************************************************************************/
   /* adjust your path to the mp3captchaform.php location */
include_once('./include/mp3captchaform.php');
   
/* init captchaform class */
$mp3captcha= new mp3captcha();
   
/* set the current url */
$mp3captcha->url = $_SERVER['SCRIPT_NAME'];
   
/* language switch */
$mp3captcha->langswitch();
if (isset(
$_GET['cfsnd'])) {
   
/* output captcha mp3 */
   
$mp3captcha->mp3stitch();
} else if (isset(
$_GET['cfimg'])) {
   
/* output captcha image */
   
$mp3captcha->image();
}
   
/* validate captcha value on post - validation can also be done on a different page
   set the $mp3captcha= new mp3captcha(); first on a different page */
if ($mp3captcha->post()) {
   
// Do your POST action here
}
?>

<?php
/********************************************************************************
* MP3 captchaform HTML - Echo this in your form
********************************************************************************/
echo $mp3captcha->html();
?>



Setup js and php code to use it as addon for an already existing session Captcha
( use the class audio option only )

<?php
   
/* Create a page for the mp3 and link to it in the below javascript
   Set the : var mp3cf to link to this page
   as sample: var mp3cf = "/captcha/index.php";
   */
include_once('./include/mp3captchaform.php');
   
/* init captchaform class */

$mp3captcha = new mp3captcha();

$your_captcha_sessionname = "captcha_session_name";
$mp3captcha->session = $your_captcha_sessionname;

   
/* create mp3 */
if (isset($_GET['cfsnd'])) {
   
$mp3captcha->mp3stitch();
}
?>

<?php
/* validation part */
if (strtolower($_POST['your_post_captcha_form_value']) == strtolower($_SESSION[$your_captcha_sessionname])) {
  echo
"It passed";
}
/**
Javascript and Html to use with your form

<script type="text/javascript"><!--
   // url of the Mp3Captcha.php ( to webroot )
   // Set the : var mp3cf to link to this page, as sample:
   var mp3cf = "/captcha/index.php";
   // click delay 1500 = 1.5 sec
   var delaytime = 2500;
   var delayer = false;
   var desoundEmbed = null;

   function captchaMp3() {
       var d = new Date();
       if (delayer) {
           return false;
       }
       delayer = true;
       setTimeout('resetdelay()', delaytime);
       if (!desoundEmbed) {
           desoundEmbed = document.createElement("embed");
           desoundEmbed.setAttribute("src", mp3cf + "?cfsnd=" + d.getTime());
           desoundEmbed.setAttribute("hidden", true);
           desoundEmbed.setAttribute("autostart", true);
           desoundEmbed.setAttribute("type", "audio/x-mpeg");
       } else {
           document.body.removeChild(desoundEmbed);
           desoundEmbed.removed = true;
           desoundEmbed = null;
           desoundEmbed = document.createElement("embed");
           desoundEmbed.setAttribute("src", mp3cf + "?cfsnd=" + d.getTime());
           desoundEmbed.setAttribute("hidden", true);
           desoundEmbed.setAttribute("autostart", true);
           desoundEmbed.setAttribute("type", "audio/x-mpeg");
       }
       desoundEmbed.removed = false;
       document.body.appendChild(desoundEmbed);
       return true;
   }
   
   function resetdelay() {
       delayer = false;
   }

//--></script>

<a href="javascript:captchaMp3();void(0)" onmouseover="window.status=''; return true;">Listen to code</a>


*/
?>


The generated sound file has a small size ( captcha with 4 characters approx 12 to 25kb ) due to mp3 format with high compression. Captcha fonts, size, length and the background images are adjustable and can be set random or fixed ( Configure as you wish.. ).
It's tested on (the latest): Firefox, Opera, Safari, Netscape and Internet Explorer browser ( Win and OSX )

      <<< To scripts      


    scripts.titude.nl 2012