找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1384|回复: 0

[分享] 织梦 dedecms 5.7 中文验证码下载

[复制链接]
发表于 2018-3-27 09:38:01 | 显示全部楼层 |阅读模式 来自 河南省新乡市
帮客户用织梦5.7做了一个中国林果网,后来有机器注册垃圾会员,尝试了很多种办法防止无效后,就从网上找了个中文验证码,运行时不对,我作了修改了后可以运行,垃圾会员也明显的少了些,现在分享出来。
把文件vdimgck.php和simhei.ttf(字体文件)放在/下,vdimgck.php文件源码如下:
代码如下       
  1. <?php
  2. /**
  3. * 验证图片
  4. * 在网上下的,经过阿亮修改
  5. * 834114969@qq.com
  6. * http://liuzhiliang.com/
  7. */
  8. require_once(dirname(__FILE__)."/common.inc.php");
  9. //Session保存路径
  10. $sessSavePath = DEDEDATA."/sessions/";
  11. if(is_writeable($sessSavePath) && is_readable($sessSavePath)){ session_save_path($sessSavePath); }
  12. if(!empty($cfg_domain_cookie)) session_set_cookie_params(0,'/',$cfg_domain_cookie);
  13. session_start();
  14. //获取随机字符
  15. $rndstring = '';
  16. //$ch_h = chr(($num,0,2)+160);
  17. //    $ch_l = chr(substr($num,2,2)+160);
  18. function c2ch($num){
  19.     $ch_h = chr(substr($num,0,2)+160);
  20.     $ch_l = chr(substr($num,2,2)+160);
  21.     return $ch_h.$ch_l;
  22. }
  23. function num_rand(){
  24.           mt_srand((double)microtime() * 1000000);
  25.           $d= mt_rand(16,36);
  26.           $n= mt_rand(1,19);
  27.           return c2ch($d*100+$n);
  28. }
  29. for($i=0; $i<4; $i++) $rndstring .= gb2utf8(num_rand());
  30. //如果支持GD,则绘图
  31. if(function_exists("imagecreate"))
  32. {
  33.     //Firefox部份情况会多次请求的问题,5秒内刷新页面将不改变session
  34.     $ntime = time();
  35.     if(empty($_SESSION['securimage_code_value_last']) || empty($_SESSION['securimage_code_value']) || ($ntime - $_SESSION['securimage_code_value_last'] > 1))
  36.     {
  37.         $_SESSION['securimage_code_value'] = strtolower($rndstring);
  38.         $_SESSION['securimage_code_value_last'] = $ntime;
  39.     }
  40.     $rndstring = $_SESSION['securimage_code_value'];
  41.     //创建图片,并设置背景色
  42.     $x_size=80;
  43.     $y_size=25;
  44.     $font='simhei.ttf';
  45.     $im=imagecreate($x_size,$y_size);
  46.     $background_color = imagecolorallocate ($im, 255, 255, 255);
  47.     // 随机颜色
  48.     $fontColor[]  = imagecolorallocate($im, 0x15, 0x15, 0x15);
  49.     $fontColor[]  = imagecolorallocate($im, 0x95, 0x1e, 0x04);
  50.     $fontColor[]  = imagecolorallocate($im, 0x93, 0x14, 0xa9);
  51.     $fontColor[]  = imagecolorallocate($im, 0x12, 0x81, 0x0a);
  52.     $fontColor[]  = imagecolorallocate($im, 0x06, 0x3a, 0xd5);
  53.     $c_fontColor = $fontColor[mt_rand(0,4)];
  54.     imagettftext($im,15,mt_rand(-8,8),6,mt_rand(19,22),$c_fontColor,$font,substr($rndstring,0,3));
  55.     imagettftext($im,15,mt_rand(-8,8),37,20,$c_fontColor,$font,substr($rndstring,6,3));
  56.     imagettftext($im,mt_rand(15,17),mt_rand(-8,8),22,20,$c_fontColor,$font,substr($rndstring,3,3));
  57.     imagettftext($im,mt_rand(15,17),mt_rand(-8,8),54,mt_rand(19,22),$c_fontColor,$font,substr($rndstring,9,3));
  58.     imagerectangle($im, 0, 0, $x_size - 1, $y_size - 1,$black);
  59.     header("Pragma:no-cachern");
  60.     header("Cache-Control:no-cachern");
  61.     header("Expires:0rn");
  62.     //输出特定类型的图片格式,优先级为 gif -> jpg ->png
  63.     if(function_exists("imagejpeg"))
  64.     {
  65.         header("content-type:image/jpegrn");
  66.         imagejpeg($im);
  67.     }
  68.     else
  69.     {
  70.         header("content-type:image/pngrn");
  71.         imagepng($im);
  72.     }
  73.     ImageDestroy($im);
  74.     exit();
  75. }
  76. else
  77. {
  78.     //不支持GD,只输出字母 ABCD
  79.     $_SESSION['securimage_code_value'] = "abcd";
  80.     $_SESSION['securimage_code_value_last'] = '';
  81.     header("content-type:image/jpegrn");
  82.     header("Pragma:no-cachern");
  83.     header("Cache-Control:no-cachern");
  84.     header("Expires:0rn");
  85.     $fp = ("data/vdcode.jpg","r");
  86.     echo fread($fp,filesize("data/vdcode.jpg"));
  87.     fclose($fp);
  88.     exit();
  89. }
  90. ?>
复制代码

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-4-26 14:09 , Processed in 0.043748 second(s), 9 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表