PHP Classes

CAPTCHA with Audio: Authenticate human users with audio CAPTCHA

Recommend this page to a friend!
  Info   View files Example   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 199 All time: 8,466 This week: 124Up
Version License PHP version Categories
captcha_sound 1.0.0GNU General Publi...5PHP 5, Audio, Validation, Security


This package can authenticate human users with audio CAPTCHA.

It provides means to verify if the current user is a real human by outputting an audio sample that represents a given validation text.

The package also provides a CAPTCHA validation variant that shows a math expression for the user to enter the respective result.

Picture of Bogdan Lupandin
Name: Bogdan Lupandin <contact>
Classes: 3 packages by
Country: United States United States
Age: 33
All time rank: 1556233 in United States United States
Week rank: 398 Up50 in United States United States Up


// Starting the session so we could access the session variables

// Including our mp3 stitching class

// The captcha word we are making the audio for
$captcha = $_SESSION['captcha_q'];

// Getting the length of the captcha
$length = strlen($captcha);

$prev_char = null;

// Stitching the MP3 files together
for($c = 0; $c < $length; $c++)
// Current character we are working with
$char = substr($captcha, $c, 1);
// Checking to make sure we don't do anything with the parenthesis
if(($char != '(') && ($char != ')'))
// If previous was an open parenthesis, then we are saying negative (instead of minus; as only negative numbers have parenthesis around them)
if($prev_char == '(')
$char = '(-';
// Initiating the first character
$mp3 = new stitch_mp3('../sounds/' . $char . '.mp3');
$mp3->append_mp3('../sounds/' . $char . '.mp3');
$prev_char = $char;

// Making sure we got this going to the browser (and not as a download)
$mp3->inline = 1;

// Output
$mp3->output(md5($captcha . time()) . '.mp3');

  Files folder image Files  
File Role Description
Files folder imageaudio (3 files)
Files folder imagecaptcha (2 files)
Plain text file captcha.php Class Main abstract class
Accessible without login Plain text file display_math.php Aux. Math captcha example
Accessible without login Plain text file display_random.php Aux. Random captcha example
Accessible without login Plain text file display_string.php Aux. String captcha example

  Files folder image Files  /  audio  
File Role Description
  Accessible without login Plain text file math_audio.php Example Generates the audio for math captcha
  Plain text file stitch_mp3.php Class MP3 stitching class
  Accessible without login Plain text file string_audio.php Example Generates the audio for string captcha

  Files folder image Files  /  captcha  
File Role Description
  Plain text file math.php Class Math captcha class
  Plain text file string.php Class String captcha class

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:8,466
This week:124Up