栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > PHP > php开源框架 > dedecms

织梦 dedecms 5.7 中文验证码下载

dedecms 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

织梦 dedecms 5.7 中文验证码下载

帮客户用织梦5.7做了一个中国林果网,后来有机器注册垃圾会员,尝试了很多种办法防止无效后,就从网上找了个中文验证码,运行时不对,我作了修改了后可以运行,垃圾会员也明显的少了些,现在分享出来。

把文件vdimgck.php和simhei.ttf(字体文件)放在/下,vdimgck.php文件源码如下:

 代码如下  


require_once(dirname(__FILE__)."/common.inc.php");
//Session保存路径
$sessSavePath = DEDEDATA."/sessions/";

if(is_writeable($sessSavePath) && is_readable($sessSavePath)){ session_save_path($sessSavePath); }
if(!empty($cfg_domain_cookie)) session_set_cookie_params(0,'/',$cfg_domain_cookie);

session_start();

//获取随机字符
$rndstring = '';
//$ch_h = chr(($num,0,2)+160);
//    $ch_l = chr(substr($num,2,2)+160);
function c2ch($num){
    $ch_h = chr(substr($num,0,2)+160);
    $ch_l = chr(substr($num,2,2)+160);
    return $ch_h.$ch_l;
}
function num_rand(){
          mt_srand((double)microtime() * 1000000);
          $d= mt_rand(16,36);
          $n= mt_rand(1,19);
          return c2ch($d*100+$n);
}

for($i=0; $i<4; $i++) $rndstring .= gb2utf8(num_rand());
//如果支持GD,则绘图
if(function_exists("imagecreate"))
{
    //Firefox部份情况会多次请求的问题,5秒内刷新页面将不改变session
    $ntime = time();
    if(empty($_SESSION['securimage_code_value_last']) || empty($_SESSION['securimage_code_value']) || ($ntime - $_SESSION['securimage_code_value_last'] > 1))
    {
        $_SESSION['securimage_code_value'] = strtolower($rndstring);
        $_SESSION['securimage_code_value_last'] = $ntime;
    }
    $rndstring = $_SESSION['securimage_code_value'];
    //创建图片,并设置背景色
    $x_size=80;
    $y_size=25;
    $font='simhei.ttf';
    $im=imagecreate($x_size,$y_size);
    $background_color = imagecolorallocate ($im, 255, 255, 255);

    // 随机颜色
    $fontColor[]  = imagecolorallocate($im, 0x15, 0x15, 0x15);
    $fontColor[]  = imagecolorallocate($im, 0x95, 0x1e, 0x04);
    $fontColor[]  = imagecolorallocate($im, 0x93, 0x14, 0xa9);
    $fontColor[]  = imagecolorallocate($im, 0x12, 0x81, 0x0a);
    $fontColor[]  = imagecolorallocate($im, 0x06, 0x3a, 0xd5);
    $c_fontColor = $fontColor[mt_rand(0,4)];

    imagettftext($im,15,mt_rand(-8,8),6,mt_rand(19,22),$c_fontColor,$font,substr($rndstring,0,3));
    imagettftext($im,15,mt_rand(-8,8),37,20,$c_fontColor,$font,substr($rndstring,6,3));
    imagettftext($im,mt_rand(15,17),mt_rand(-8,8),22,20,$c_fontColor,$font,substr($rndstring,3,3));
    imagettftext($im,mt_rand(15,17),mt_rand(-8,8),54,mt_rand(19,22),$c_fontColor,$font,substr($rndstring,9,3));
    imagerectangle($im, 0, 0, $x_size - 1, $y_size - 1,$black);

    header("Pragma:no-cachern");
    header("Cache-Control:no-cachern");
    header("Expires:0rn");

    //输出特定类型的图片格式,优先级为 gif -> jpg ->png
    if(function_exists("imagejpeg"))
    {
        header("content-type:image/jpegrn");
        imagejpeg($im);
    }
    else
    {
        header("content-type:image/pngrn");
        imagepng($im);
    }
    ImageDestroy($im);
    exit();
}
else
{
    //不支持GD,只输出字母 ABCD
    $_SESSION['securimage_code_value'] = "abcd";
    $_SESSION['securimage_code_value_last'] = '';
    header("content-type:image/jpegrn");
    header("Pragma:no-cachern");
    header("Cache-Control:no-cachern");
    header("Expires:0rn");
    $fp = ("data/vdcode.jpg","r");
    echo fread($fp,filesize("data/vdcode.jpg"));
    fclose($fp);
    exit();
}

?>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/3052.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号