DEDECMS这个不用多讲了,用过的都知道, 最近经常遇上注册机或是发帖机器人, 垃圾信息太多很难处理,于是想到给验证码加大难度, 终于找到了一种办法, 感谢前面各位大侠的劳动成果,在这里做下总结, 保证亲们能用。
首先找到文件include/vdimgck.php ,打开,用以下内容替换
<?php
//Session保存路径
$sessSavePath = dirname(__FILE__)."/../data/sessions/";
if(is_writeable($sessSavePath) && is_readable($sessSavePath)){ session_save_path($sessSavePath); }
session_start();
include_once(dirname(__FILE__) . '/common.inc.php');
include_once(dirname(__FILE__) . '/charset.func.php');
$xt_vdimg_zh=array('宠', '辱', '不', '惊', '静', '看', '庭', '前', '花', '开',
'花', '零', '度', '空', '间', '幽', '暗', '之', '灵', '唐', '啸', '天', '落',
'得', '失', '无', '意', '漫', '望', '天', '外', '云', '卷', '云', '舒');
//生成附加码,以上的文件可以随便改哦
function create_excode($length){
global $xt_vdimg_zh;
header("content-type: image/png");
$image_x = $length * 30; //图片宽度
$image_y = 40; //图片高度
$noise_num = 80 * $length; //杂点数量
$line_num = $length - 2; //干扰线数量
$image = imagecreate($image_x, $image_y);
imagecolorallocate($image,0xff, 0xff, 0xff); //设定背景颜色
$rectangle_color = imagecolorallocate($image,0xAA, 0xAA, 0xAA); //边框颜色
$noise_color = imagecolorallocate($image,0x00, 0x00, 0x00); //杂点颜色
$font_color = imagecolorallocate($image,0x00, 0x00, 0x00); //字体颜色
$line_color = imagecolorallocate($image,0x33, 0x33, 0x33); //干扰线颜色
//加入杂点
for($i=0; $i < $noise_num; $i++)
imagesetpixel($image, mt_rand(0,$image_x), mt_rand(0,$image_y), $noise_color);
$font_face = DEDEINC . "/data/simsun.ttc"; //字体
$x = 2;
$session_code = '';
for($i=0; $i<$length; $i++){
$code = $xt_vdimg_zh[mt_rand(0,count($xt_vdimg_zh)-1)];
imagettftext($image, 18, mt_rand(-6, 6), $x, 29, $font_color, $font_face, gb2utf8($code));
$x += 30;
$session_code .= $code;
}
$_SESSION['dd_ckstr'] = $session_code; //把附加码的值放在session中
//加入干扰线
for($i=0; $i < $line_num; $i++)
imageline($image, mt_rand(0, $image_x), mt_rand(0, $image_y),
mt_rand(0, $image_x), mt_rand(0,$image_y), $line_color);
imagerectangle($image, 0, 0, $image_x-1, $image_y-1, $rectangle_color); //加个边框
imagepng($image);
imagedestroy($image);
}
create_excode(4);
?>
经测试 DedeCms5.3 GBK,DedeCms5.5 GBK,DedeCms5.5 UTF-8 都可以使用
注意UTF-8使用时将:
gb2utf8($code) 替换为$code
在create_excode函数中
最后还要随便下载一个中文的字体文件放到include中的data目录(注意命名为simsun.ttc)。
保存后,就可以使用了!
DEDE 5.3 5.5 5.7可以使用!