Example #1
0
 /**
  * 验证码
  *
  */
 public function verifycode()
 {
     import('@.ORG.Seccode');
     import('@.ORG.SeccodeUtil');
     @ob_end_clean();
     //清除之前出现的多余输入
     $seccode = SeccodeUtil::make_seccode(CAPTCHA_CODE);
     //随机生成验证码内容并保存到session中
     $code = new Seccode();
     $code->root_path = APP_PATH;
     $code->code = $seccode;
     //验证码内容
     $code->type = 0;
     //验证码类型,0:英文图片、1:中文图片、2:Flash 验证码、3:语音验证码、4:位图验证码
     $code->width = $this->_CFG['captcha_width'];
     //验证码宽度
     $code->height = $this->_CFG['captcha_height'];
     //验证码高度
     $code->background = 0;
     //随机图片背景
     $code->adulterate = 1;
     //随机背景图形
     $code->ttf = 1;
     //验证码
     $code->angle = 0;
     //随机倾斜度
     $code->color = 1;
     //随机颜色
     $code->size = 0;
     //随机大小
     $code->shadow = 1;
     //文字阴影
     $code->animator = 1;
     //GIF 动画
     $code->warping = 0;
     //随机扭曲
     $code->fontpath = LIB_PATH . '/ORG/seccode/font/';
     //字体包路径
     $code->datapath = LIB_PATH . '/ORG/seccode/';
     //背景图片、字体、声音等文件路径
     $code->includepath = LIB_PATH . '/ORG/';
     $code->display();
 }
Example #2
0
 /**
  * @param string $length  字符串长度
  * @param string $mode  类型 0:大小写混写 1:纯数字 2:全部大写 3:全小写 4:汉字
  * @param string $type 图像格式
  * @param string $width  宽度
  * @param string $height  高度
  */
 static function buildImageVerify($length = 4, $mode = 1, $width = 48, $height = 22, $verifyName = 'checkcode')
 {
     session_start();
     //生成随机数
     $randval = self::rand_string($length, $mode);
     //写入session 或写入全局变量
     $_SESSION[$verifyName] = $randval;
     //确定图片最适合长度
     $width = $length * 10 + 10 > $width ? $length * 10 + 10 : $width;
     $im = imagecreatetruecolor($width, $height);
     $r = array(225, 255, 255, 223);
     $g = array(225, 236, 237, 255);
     $b = array(225, 236, 166, 125);
     //生成随机数
     $key = mt_rand(0, 3);
     //为图像分配颜色
     $backColor = imagecolorallocate($im, 225, 225, 225);
     //背景色(随机)
     $borderColor = imagecolorallocate($im, 100, 100, 100);
     //边框色
     $pointColor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
     //点颜色
     // 画一矩形并填充
     @imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
     // 画一个矩形
     @imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
     // 分配颜色
     $stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
     // 圆弧干扰
     for ($i = 0; $i < 10; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor);
     }
     // 点干扰
     for ($i = 0; $i < 25; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pointColor);
     }
     // 不水平画
     for ($i = 0; $i < $length; $i++) {
         $temp = $width / $length;
         $size = mt_rand(4, 5);
         imagestring($im, $size, $i * $temp + 5, mt_rand(1, 5), $randval[$i], $stringColor);
     }
     Seccode::output($im);
     exit;
 }