PHP驗證碼工具-Securimage
最近項目中接觸到了一個新的php驗證碼工具 -Securimage,使用起來非常簡單和方便,并且支持ajax調用,因此在這里給大家推薦一下。
什么是Securimage?
Securimage是一個開源/免費的phpCAPTCHA腳本,它可以用來生成復雜的驗證碼圖片,幫助您的網站防止spam。它可以輕松嵌入網站已存的表單中,為您的網站提供spam機器人的防護。它可以運行于大部分支持php(GD)的webserver上。
*點擊這里查看快速指南*Securimage實例*下載最新版本
Securimage的特性:
* 僅用三行代碼即可顯示驗證碼* 僅用六行代碼即可對驗證碼的輸入進行驗證* 自定義驗證碼長度* 自定義字符集* 支持TTF* 使用自定義的GD字體(若TTF不支持)* 輕松添加自定義背景圖片* 豐富的文本支持,包括顏色/角度/透明度選項* 文字淆亂Arched lines through text* 生成wav格式的CAPTCHA音頻文件* 自定義CAPTCHA的驗證碼列表
下面給大家一個簡單的例子:
<html><head> <title>Securimage Test Form</title></head><body><?phpif (empty($_POST)){?><form method='POST'>Username:<br /><input type='text' name='username' /><br />Password:<br /><input type='text' name='password' /><br /><!-- 調用securimage,顯示驗證碼圖片,sid是用來防止被cache住的 --><img src='http://www.cgvv.com.cn/bcjs/securimage_show.php?sid=<?php echomd5(uniqid(time()));?>'><br /><input type='text' name='code' /><br /><input type='submit' value='Submit Form' /></form><?php} else{//form is postedinclude('securimage.php');$img=new Securimage();$valid=$img->check($_POST['code']);//檢查用戶的輸入是否正確if($valid==true) { echo '<center>Thanks, you entered the correct code.</center>';} else{ echo '<center>Sorry, the code you entered was invalid.; <a href='javascript:history.go(-1)'>Go back</a> to try again.</center>';}}?></body></html>securimage_show.php的代碼:
<?phpinclude 'securimage.php';//下載包里面的核心類庫代碼$img=new securimage();$img->show();// alternate use:; $img->show('/path/to/background.jpg');?>