frontend目录下/封装的验证码类:
<?php
namespace frontend\controllers;      

use yii\base\Controller;

class CapathController extends Controller
{

;;;;;
;,,), mt_rand(,), mt_rand(,));
imagefilledrectangle(,,;,),mt_rand(,),mt_rand(,));
imagettftext(,),,),;;,),mt_rand(,),mt_rand(,));
imageline(,,,,;;,),mt_rand(,),mt_rand(,));
imagestring(,),mt_rand(,,$this->height),'*',$color);
}
}
//输出
private function outPut() {
header('Content-type:image/png');
imagepng($this->img);
imagedestroy($this->img);
}
//对外生成(主方法)
public function doimg() {
$this->createBg(); //调用生成背景
$this->createCode(); //调用生成随机码
$this->createLine(); //调用生成线条、雪花
$this->createFont(); //调用生成文字
$this->outPut(); //调用输出方法
}
//获取验证码
public function getCode() {
return strtolower($this->code);
}
}
?>

控制器下调用:
<?php

use frontend\controllers\CapathController;
//定义生成验证码方法
public function actionCreatecapath()
{
   //开启session
   \Yii::$app->session->open();
   //输出图像
   $capthObj = new CapathController();
   $capthObj->doimg();
   //存验证码
   $_SESSION['capath'] = $capthObj->getCode();//获取验证码保存到SESSION中
}

?>

视图层:

<px;cursor:pointer;" onclick="this.src='?r=上面控制器/createcapath&'+Math.random();">

最新文章

  1. JavaScript中的变量及数据类型
  2. [Unity] 精灵动画制作中需要注意的一些问题
  3. Cygwin的安装与配置
  4. 1.No MBR错误
  5. SplendidCRM 如何添加及使用中文语言包
  6. elementoryOS / ubuntu U盘启动问题的解决
  7. 在集群环境中使用 EhCache 缓存系统|RMI 集群模式
  8. Buffer -nodejs
  9. PV模型
  10. poj 2250 Compromise(区间dp)
  11. HTML5总结
  12. 关于HashSet集合add元素
  13. go 语言图片像素点处理
  14. XXS level9
  15. Apache POI导出excel表格
  16. 卡通渲染Shader
  17. [No0000187]可能是把Java内存区域讲的最清楚的一篇文章
  18. ES6学习笔记四:Proxy与Reflect
  19. Shell if else
  20. 【性能测试】:解决loadrunner执行脚本启动慢的问题

热门文章

  1. 让html页面不缓存js的实现方法
  2. AVL树,红黑树,B树,B+树,Trie树都分别应用在哪些现实场景中?
  3. Core Graphics框架 利用Quartz 2D绘图
  4. Unity 围绕X、Y、Z旋转图例
  5. 页面定制CSS代码初探(一):页面变宽 文本自动换行 图片按比缩放
  6. JSP 点击量统计!
  7. spring使用注解开发
  8. 如何降低死循环的 CPU 占用
  9. php5 中魔术方法函数有哪几个
  10. MyBatis学习总结(6)——调用存储过程