首先使用Composer安裝think-captcha擴展包:
composer require topthink/think-captcha
在安裝擴展的目錄下有think-captcha文件夾
對于不能顯示驗證碼的問題
在 think-captcha/src/helper.php? 第39行
添加$root=?\think\Url::root('/index.php');
使得固定根路徑,這樣就可以正確顯示驗證碼了
修改 captcha_img 函數以期達到模板中只要添加{:captcha_img()}就可以點擊更換驗證碼function?captcha_img($id?=?"")
{
????return?'<img?src="'?.?captcha_src($id)?.?'"??alt="點擊更換"??onclick="this.src=\''.captcha_src().'?id=\'+Math.random();"?/>';
}