標籤:des style blog http io ar color sp java
1,在home模組indexController.class.php中,加入以下代碼
<?phpnamespace Home\Controller;use Think\Controller;class BookController extends Controller { public function verify_c(){ $Verify = new \Think\Verify(); $Verify->fontSize = 18; $Verify->length = 4; $Verify->useNoise = false; $Verify->codeSet = ‘0123456789‘; $Verify->imageW = 130; $Verify->imageH = 50; //$Verify->expire = 600; $Verify->entry(); } public function img(){ $this->display(); }}
2. 在img 視圖中,加入以下代碼
<script type="text/javascript" src="__PUBLIC__/js/jquery2.0.3.min.js"></script><p class="top15 captcha" id="captcha-container"> <input name="verify" width="50%" height="50" class="captcha-text" placeholder="驗證碼" type="text"> <img width="100" class="left15" height="50" alt="驗證碼" src="{:U(‘Home/Book/verify_c‘,array())}" title="點擊重新整理"></p> <script type="text/javascript"> $(function(){ var captcha_img = $(‘#captcha-container‘).find(‘img‘); var verifyimg = captcha_img.attr("src"); captcha_img.attr(‘title‘, ‘點擊重新整理‘); captcha_img.click(function(){ if( verifyimg.indexOf(‘?‘)>0){ $(this).attr("src", verifyimg+‘&random=‘+Math.random()); }else{ $(this).attr("src", verifyimg.replace(/\?.*$/,‘‘)+‘?‘+Math.random()); } }); }) </script>
這樣就可以了,就能顯示出 驗證碼了。
參考學習 網址:http://blog.csdn.net/yafei450225664/article/details/40424025
Thinkphp 3.2 添加 驗證碼 如何添加。