Source for file captcha-audio.php

Documentation is available at captcha-audio.php

  1. <?php
  2. /**
  3. * Captcha audio handling for Mambo
  4. @package Mambo
  5. @author Mambo Foundation Inc see README.php
  6. @copyright Mambo Foundation Inc.
  7. *  See COPYRIGHT.php for copyright notices and details.
  8. @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see
  9. *  LICENSE.php
  10. *  Mambo is free software; you can redistribute it and/or
  11. *  modify it under the terms of the GNU General Public License
  12. *  as published by the Free Software Foundation; version 2 of the
  13. *  License.
  14. */
  15.  
  16. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  17.  
  18. global $mosConfig_lang$mosConfig_absolute_path;
  19.  
  20. session_name('mos_captcha');
  21. $code $_SESSION['code'];
  22.  
  23. // language select (for future addition of own wav files)
  24. $lang $mosConfig_absolute_path.'/includes/captchaAudio/'.$mosConfig_lang.'/';
  25. if (!is_dir($lang)) {
  26.     $lang $mosConfig_absolute_path.'/includes/captchaAudio/en/';
  27. }
  28.  
  29. $wavs array();
  30.  
  31. for($i=0;$i<5;$i++){
  32.     $file $lang.$code{$i}.'.wav';
  33.     $wavs[$file;
  34. }
  35.  
  36. //$totalsize = filesize($filename);
  37. header("Cache-Control: no-cache, must-revalidate");
  38. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  39. header('Content-type: audio/x-wav');
  40. header("Content-Transfer-Encoding: binary");
  41. //header("Content-Length: ".$totalsize);
  42. header('Content-Disposition: attachment;filename=captcha.wav');
  43.  
  44. echo joinwavs($wavs);
  45.  
  46. /**
  47.  * CAPTCHA antispam plugin - sound generator
  48.  * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
  49.  * @author     Andreas Gohr <gohr@cosmocode.de>
  50.  */
  51.  
  52. function joinwavs($wavs){
  53.     $fields join('/',array'H8ChunkID''VChunkSize''H8Format',
  54.                               'H8Subchunk1ID''VSubchunk1Size',
  55.                               'vAudioFormat''vNumChannels''VSampleRate',
  56.                               'VByteRate''vBlockAlign''vBitsPerSample' ));
  57.  
  58.     $data '';
  59.  
  60.     foreach($wavs as $wav){
  61.         $fp     fopen($wav,'rb');
  62.         $header fread($fp,36);
  63.         $info   unpack($fields,$header);
  64.         if($info['Subchunk1Size'16){
  65.             $header .= fread($fp,($info['Subchunk1Size']-16));
  66.         }
  67.         $header .= fread($fp,4);
  68.         $size  unpack('vsize',fread($fp4));
  69.         $size  $size['size'];
  70.         $data .= fread($fp,$size);
  71.     }
  72.  
  73.     return $header.pack('V',strlen($data)).$data;
  74. }
  75.  
  76. ?>

Documentation generated on Mon, 05 May 2008 16:16:49 +0400 by phpDocumentor 1.4.0