[PHP+FLASH]语音验证码(voice verification code)
看到很多国外网站上开始有了语音验证码功能,觉得挺好玩,而且也方便一些视力不好的人士,所以自己也尝试做了一个玩玩,是用的PHP+FLASH完成的,主要代码如下:
PHP文件 <?PHP
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */ /** * @Name voice_code.php * @Note 语音验证码 * @Author arcow@21xp.com * @Created 2007/4/26 * @Version 1.0 * */ header('Content-type: audio/mpeg'); //随机种子 list($usec, $sec) = explode(' ', microtime()); $randtime = (float) $sec + ((float) $usec * 100000); srand($randtime); //随机验证码 $authnum = ''; //$str = 'abcdefghijkmnpqrstuvwxyz1234567890'; $str = '1234567890'; $l = strlen($str); for($i=1;$i<=4;$i++) { $num=rand(0,$l); $authnum.= $str[$num]; } //把随机验证码记录到session $_SESSION['auth_code'] = $authnum; //转成字符串,方便用数组调用 $code = strval($authnum); readfile("sound/begin.mp3"); for($i=0;$i<strlen($code);$i++) { $soundNum = $code[$i]; readfile("sound/$soundNum.mp3"); } readfile("sound/end.mp3"); ?> Html文件 <html>
<head> <title>语音验证码示例文件(voice verification code Sample) by arcow@21xp.com</title> <script language="javascript"> var myimages=new Array(); function preloadimages() { for (i=0;i<preloadimages.arguments.length;i++) { myimages[i]=new Image(); myimages[i].src=preloadimages.arguments[i] } } preloadimages("sound/audio.jpg"); </script> </head> <body> <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="0" height="0" id="code_play" align="middle"> <param name="allowScriptAccess" value="always" /> <param name="FlashVars" value="url=voice_code.php" /> <param name="movie" value="code_play.swf"/> <param name="quality" value="high" /> <param name="bgcolor" value="#ffffff" /> <embed id="code_play" name="code_play" src="code_play.swf" FlashVars="url=voice_code.php" quality="high" bgcolor="#ffffff" width="0" height="0" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object> <script language="javascript"> function readVoiceCode() { document.getElementById('code_img').src = "sound/audio.jpg"; document.getElementById('againListen').style.display=''; document.getElementById('readVoiceBtn').style.display='none'; window.document.code_play.SetVariable("isPlay", "1"); } </script> <a href="javascript:void(0);" onclick="javascript:readVoiceCode();" id="readVoiceBtn">读语音验证码</a> <a href="javascript:void(0);" onclick="javascript:readVoiceCode();" id="againListen" style="display:none;">没听清?再听一次</a> <img src='sound/default.jpg' id="code_img"> </body> </html> 全部源码包(PHP,FLASH,声音文件等源文件)下载地址为:http://bbs.chinaunix.net/viewthread.php?tid=928953&extra=page%3D1 最早发于:2007-04-26 15:07:00 |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步