1. 程式人生 > >TP5 驗證碼

TP5 驗證碼

示例前端:

<input type="text" name="cod" placeholder="請輸入驗證碼"> //name='cod'
<div id="captcha_id">{:captcha_img()}</div> 
js重新整理驗證碼:
$('#captcha_id').click(function () {
    $(this).find('img').attr('src','/captcha.html?r='+Math.random());
});

控制器:

$cod = input('cod');
if (!captcha_check($cod)) {
    return show('-1', '驗證碼錯誤'); //show 公共檔案自定方法
} else {
   //邏輯處理
}