ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
> 关于图形验证,您可以使用第三方库来进行实现 > 以下路径需要替换成您自己的目录 ### 安装: **Linux**中执行: ``` cd /www/wwwroot/test.com composer require lifei6671/php-captcha ``` 完成后如图所示 ![](https://img.kancloud.cn/77/0f/770f03614e7dcbd46f3cf496124a25e7_705x208.png) ***** **Windows**中打开cmd,分别执行 ``` cd /d D:\code\PHP\PHP300Framework2x composer require lifei6671/php-captcha ``` 完成后如图所示 ![](https://img.kancloud.cn/91/09/9109a8b52c611f9a741047cad6e38d5d_794x285.png) ### 使用: 首先需要在控制器中引入命名空间: ~~~ use Minho\Captcha\CaptchaBuilder; ~~~ 然后在您的方法中使用: ~~~ //创建 $captch = new CaptchaBuilder(); $captch->initialize([ 'width' => 150, // 宽度 'height' => 50, // 高度 'line' => false, // 直线 'curve' => true, // 曲线 'noise' => 1, // 噪点背景 'fonts' => [] // 字体 ]); //创建实例 $captch->create(); //保存到session $code= $captch->getText(); Session()->set('code',$code); //输出图片 $captch->output(1); /** $captch->save('1.png',1); //这里是保存验证码图片到文件 **/ ~~~ 上面是创建验证码,并且将验证码文本储存到session中,当需要验证的时候可以使用`Session()->get('code');`取出验证码文本作比较即可 ![](https://img.kancloud.cn/d4/11/d411b9fc4a4e0e31933a754668a16585_1002x231.png)