*********************
[Hack]随机长度的数字验证码
功能描述:每次刷新都会产生2~9位的数字验证码!
作者:badfox
指导:习明
备注:
跟1楼的作用一样,只是在服务器不支持GD库函数情况下,生成更为美观的验证码!
缺点是服务器不支持GD库函数情况下所生成的美观验证码,不能点击刷新!(还没想到解决办法,欢迎讨论!)
**********************
---全新安装开始:
一、升级数据库:- ALTER TABLE `cdb_sessions` CHANGE `seccode` `seccode` bigint(12) UNSIGNED NOT NULL DEFAULT '0' ;
复制代码 二、打开global.func.php
查找:- if(!defined('IN_DISCUZ')) {
- exit('Access Denied');
- }
复制代码 下面添加:- function seccodelen() {
-
- mt_srand((double)microtime() * 1000000);
- $seccodelen = mt_rand(2,9);
- return $seccodelen;
- }
复制代码 查找:(有两处)替换为:- $seccode = random(seccodelen(), 1);
复制代码 三、打开 seccode.php
全选,全部替换为:- <?php
- /*
- [Discuz!] (C)2001-2006 Comsenz Inc.
- This is NOT a freeware, use is subject to license terms
- $RCSfile: seccode.php,v $
- $Revision: 1.11.2.1 $
- $Date: 2006/12/12 $
- */
- define('CURSCRIPT', 'seccode');
- require_once './include/common.inc.php';
- if(preg_replace("/https?:\/\/([^\:\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) != preg_replace("/([^\:]+).*/", "\\1", $_SERVER['HTTP_HOST'])) {
- exit('Access Denied');
- }
- if($update) {
- $seccode = random(seccodelen(), 1);
- updatesession();
- }
- if($seccode < 1 || $seccode > 999999999) {
- exit('Access Denied');
- }
- $seclen = strlen($seccode);
- $seccode = sprintf('%02d', $seccode);
- $image_x = $seclen*15;
- $image_y = 25;
- if(!$nocacheheaders) {
- @header("Expires: -1");
- @header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
- @header("Pragma: no-cache");
- }
- if($gdyn){
- $im = imagecreate($image_x, $image_y);
- $backgroundcolor = imagecolorallocate ($im, 255, 255, 255);
- $numorder = range(1, $seclen);
- shuffle($numorder);
- $numorder = array_flip($numorder);
- for($i = 1; $i <= $seclen; $i++) {
- $imcodefile = 'images/common/number'.$seccode[$numorder[$i]].'.gif';
- $x = $numorder[$i] * 13 + mt_rand(0, 4) - 2;
- $y = mt_rand(0, 3);
- if(file_exists($imcodefile)) {
- $imcode = imagecreatefromgif($imcodefile);
- $data = getimagesize($imcodefile);
- imagecolorset($imcode, 0 ,mt_rand(50, 255), mt_rand(50, 128), mt_rand(50, 255));
- imagecopyresized($im, $imcode, $x, $y, 0, 0, $data[0] + mt_rand(0, 6) - 3, $data[1] + mt_rand(0, 6) - 3, $data[0], $data[1]);
- } else {
- $text_color = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 128), mt_rand(50, 255));
- imagechar($im, 5, $x + 5, $y + 3, $seccode[$numorder[$i]], $text_color);
- }
- }
- $linenums = mt_rand(10, 32);
- for($i=0; $i <= $linenums; $i++) {
- $linecolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
- $linex = mt_rand(0, $image_x);
- $liney = mt_rand(0, $image_y);
- imageline($im, $linex, $liney, $linex + mt_rand(0, 4) - 2, $liney + mt_rand(0, 4) - 2, $linecolor);
- }
- for($i=0; $i <= 64; $i++) {
- $pointcolor = imagecolorallocate($im, mt_rand(50, 255), mt_rand(50, 255), mt_rand(50, 255));
- imagesetpixel($im, mt_rand(0, $image_x), mt_rand(0, $image_y), $pointcolor);
- }
- $bordercolor = imagecolorallocate($im , 150, 150, 150);
- imagerectangle($im, 0, 0, $image_x-1, $image_y-1, $bordercolor);
- header('Content-type: image/png');
- imagepng($im);
- imagedestroy($im);
- } else {
- /****************
- 这里原先的代码是在系统不支持GD库情况下由Xbm原理生成验证码图像,由于我根本不了解PHP生成Xbm的原理,所以找来了
- [太阳雨@喜悦国际村]
- 做的一个由表格生成验证码的程序,十分另类,好像也很有效,生成的验证码是由表格组成的!
- 要想强制看效果的话,把common.inc.php最后面加的那个if()判断后面加上
- $gdyn=0;
- *****************/
- $num = array(
- "0"=>array(12,13,14,15,16,22,26,32,36,42,46,52,56,62,66,72,73,74,75,76),
- "1"=>array(12,22,32,42,52,62,72),
- "2"=>array(12,13,14,15,16,26,36,42,43,44,45,46,52,62,72,73,74,75,76),
- "3"=>array(12,13,14,15,16,26,36,42,43,44,45,46,56,66,72,73,74,75,76),
- "4"=>array(12,16,22,26,32,36,42,43,44,45,46,56,66,76),
- "5"=>array(12,13,14,15,16,22,32,42,43,44,45,46,56,66,72,73,74,75,76),
- "6"=>array(12,13,14,15,16,22,32,42,43,44,45,46,52,56,62,66,72,73,74,75,76),
- "7"=>array(12,13,14,15,16,26,36,46,56,66,76),
- "8"=>array(12,13,14,15,16,22,26,32,36,42,43,44,45,46,52,56,62,66,72,73,74,75,76),
- "9"=>array(12,13,14,15,16,22,26,32,36,42,43,44,45,46,56,66,72,73,74,75,76)
- );
- echo "document.writeln(\"<table border=0 style='line-height:0.8;letter-spacing:0.8;font-size:4px'><tr>\");";
- for($i=0;$i<$seclen;$i++){
- echo "document.writeln(\"<td>\");";
- for($j=0;$j<9;$j++){
- for($k=0;$k<9;$k++){
- $v = $j.$k;
- if(in_array($v,$num[$seccode[$i]])) echo "document.writeln(\"<font style='font-color:#ff0000;'><B>O</B></font>\");";
- else echo "document.writeln(\"<B> </B>\");";
- }
- echo "document.writeln(\"<br>\");";
- }
- echo "document.writeln(\"</td>\");";
- }
- echo "document.writeln(\"</tr></table>\");";
- }
- ?>
复制代码 四、打开register.php
查找:替换为:- $seccode = random(seccodelen(), 1);
复制代码 五、打开common.inc.php查找上面添加- if(function_exists('imagecreate') && function_exists('imagecolorset') && function_exists('imagecopyresized') && function_exists('imagecolorallocate') && function_exists('imagesetpixel') && function_exists('imagechar') && function_exists('imagecreatefromgif') && function_exists('imagepng')){
- $gdyn = 1;
- }else{
- $gdyn = 0;
- }
复制代码 查找:- $_DSESSION['seccode'] = random(4, 1);
复制代码 替换为:- $_DSESSION['seccode'] = random(seccodelen(), 1);
复制代码 六、打开register.htm
查找- <!--{if $seccodecheck}-->
- <tr>
- <td class="altbg1" width="21%"><span class="bold">{lang seccode}</span></td>
- <td class="altbg2"><div class="input"><input type="text" name="seccodeverify" size="4" maxlength="4" id="seccodeverify" onBlur="checkseccode()"> <img id="seccode" style="cursor:pointer" onclick="this.src='seccode.php?update=' + Math.random()" src="seccode.php" class="absmiddle" alt="" /></div><div class="notice" id="checkseccode"> {lang secode_refresh}</div>
- <script type="text/javascript">$('seccode').src = 'seccode.php?update=' + Math.random()</script></td>
- </tr>
- <!--{/if}-->
复制代码 替换为:- <!--{if $seccodecheck}-->
- <tr><td class="altbg1" width="21%"><span class="bold">{lang seccode}</span></td>
- <td class="altbg2"><div class="input"><div style="float:left"><input type="text" name="seccodeverify" size="9" maxlength="9" id="seccodeverify" onBlur="checkseccode()"> </div> <!--{if $gdyn}--><img id="seccode" style="cursor:pointer" onclick="this.src='seccode.php?update=' + Math.random()" src="seccode.php" class="absmiddle" alt="" /><!--{else}--><div style="cursor:pointer;float:left; border: solid;border-width: 1px; "><script language="JavaScript" src="seccode.php"></script></div><!--{/if}--></div><div class="notice" id="checkseccode"> <!--{if $gdyn}-->{lang secode_refresh}<!--{else}-->请输入你看到的数字!<!--{/if}--></div><script type="text/javascript">$('seccode').src = 'seccode.php?update=' + Math.random()</script></td></tr>
- <!--{/if}-->
复制代码 查找:- var profile_seccode_invalid = '{lang register_profile_seccode_invalid}';
复制代码 替换为:- var profile_seccode_invalid = '验证码为阿拉伯数字,请正确填写。如看不清图片中的文字请点击图片刷新验证码。';
复制代码 查找:- if(!(/[0-9]{4}/.test(seccodeverify))) {
复制代码 替换为:- if(!(/^[0-9]*$/.test(seccodeverify))) {
复制代码 ---全新安装结束!
[ 本帖最后由 badfox 于 2006-12-12 16:19 编辑 ] |