PHP驗(yàn)證碼工具-Securimage
最近項(xiàng)目中接觸到了一個(gè)新的php驗(yàn)證碼工具 -Securimage,使用起來(lái)非常簡(jiǎn)單和方便,并且支持ajax調(diào)用,因此在這里給大家推薦一下。
什么是Securimage?
Securimage是一個(gè)開(kāi)源/免費(fèi)的phpCAPTCHA腳本,它可以用來(lái)生成復(fù)雜的驗(yàn)證碼圖片,幫助您的網(wǎng)站防止spam。它可以輕松嵌入網(wǎng)站已存的表單中,為您的網(wǎng)站提供spam機(jī)器人的防護(hù)。它可以運(yùn)行于大部分支持php(GD)的webserver上。
*點(diǎn)擊這里查看快速指南*Securimage實(shí)例*下載最新版本
Securimage的特性:
* 僅用三行代碼即可顯示驗(yàn)證碼* 僅用六行代碼即可對(duì)驗(yàn)證碼的輸入進(jìn)行驗(yàn)證* 自定義驗(yàn)證碼長(zhǎng)度* 自定義字符集* 支持TTF* 使用自定義的GD字體(若TTF不支持)* 輕松添加自定義背景圖片* 豐富的文本支持,包括顏色/角度/透明度選項(xiàng)* 文字淆亂Arched lines through text* 生成wav格式的CAPTCHA音頻文件* 自定義CAPTCHA的驗(yàn)證碼列表
下面給大家一個(gè)簡(jiǎn)單的例子:
<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 /><!-- 調(diào)用securimage,顯示驗(yàn)證碼圖片,sid是用來(lái)防止被cache住的 --><img src='http://www.aoyou183.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';//下載包里面的核心類庫(kù)代碼$img=new securimage();$img->show();// alternate use:; $img->show('/path/to/background.jpg');?>
