这段 JS 代码有两个含义:
一是通过 ajaxget 请求了 misc.php?mod=seccode&action=update&idhash=xxxx 这样一个地址
二是设定了一个
定时器
,从显示了验证码开始,3分钟后自动将验证码图片换为“刷新验证码”的文字,点击该文字就执行 updateseccode 这个函数,重新更新验证码。由此可以看出,此种方式可以很好的解决验证码过期的问题。
3)找到通过 ajaxget 请求的程序 source/module/misc/misc_seccode.php
通过 url 中的 action=update 可以看出,应该查看 if($_G['gp_action'] == 'update') { …… } 中的一段
if($_G['gp_action'] == 'update') {
$message = '';
if($_G['setting']['seccodestatus']) {
$rand = random(5, 1);
$flashcode = '';
$idhash = isset($_G['gp_idhash']) ? $_G['gp_idhash'] : '';
$ani = $_G['setting']['seccodedata']['animator'] ? '_ani' : '';
if($_G['setting']['seccodedata']['type'] == 2) {
……
} elseif($_G['setting']['seccodedata']['type'] == 3) {
…...
} else {
$message = lang('core', 'seccode_image'.$ani.'_tips').'<img onclick="updateseccode(''.$idhash.'')" width="'.$_G['setting']['seccodedata']['width'].'" height="'.$_G['setting']['seccodedata']['height'].'" src="misc.php?mod=seccode&update='.$rand.'&idhash='.$idhash.'" class="vm" alt="" />';
}
}
include template('common/header_ajax');
echo lang('message', $message, array('flashcode' => $flashcode, 'idhash' => $idhash));
include template('common/footer_ajax');
}
默 认设置的“英文图片验证码”的 $_G['setting']['seccodedata']['type'] 为 0,所以看 else 的部分。仔细看这里就是按照 ajax 的格式返回了一个验证码的图片,但是图片的 src 为 misc.php?mod=seccode&update=$rand&idhash=$idhash 这样一个动态链接,所以是通过这个链接动态生成的图片,此时又产生了一个新的请求。
4)找到通过图片链接请求的程序 source/module/misc/misc_seccode.php(和上面是同一个文件)
通过 url 可以看出,应该查看 if($_G['gp_action'] == 'update') { …… } else { …… } 中的一段
} else {
$refererhost = parse_url($_SERVER['HTTP_REFERER']);
$refererhost['host'] .= !empty($refererhost['port']) ? (':'.$refererhost['port']) : '';
if($_G['setting']['seccodedata']['type'] < 2 && ($refererhost['host'] != $_SERVER['HTTP_HOST'] || !$_G['setting']['seccodestatus']) || $_G['setting']['seccodedata']['type'] == 2 && !extension_loaded('ming') && $_POST['fromFlash'] != 1 || $_G['setting']['seccodedata']['type'] == 3 && $_GET['fromFlash'] != 1) {
exit('Access Denied');
}
$seccode = make_seccode($_G['gp_idhash']);
if(!$_G['setting']['nocacheheaders']) {
@header("Expires: -1");
@header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
@header("Pragma: no-cache");
}
require_once libfile('class/seccode');
$code = new seccode();
$code->code = $seccode;
$code->type = $_G['setting']['seccodedata']['type'];
$code->width = $_G['setting']['seccodedata']['width'];
$code->height = $_G['setting']['seccodedata']['height'];
$code->background = $_G['setting']['seccodedata']['background'];
$code->adulterate = $_G['setting']['seccodedata']['adulterate'];
$code->ttf = $_G['setting']['seccodedata']['ttf'];
$code->angle = $_G['setting']['seccodedata']['angle'];
$code->warping = $_G['setting']['seccodedata']['warping'];
$code->scatter = $_G['setting']['seccodedata']['scatter'];
$code->color = $_G['setting']['seccodedata']['color'];
$code->size = $_G['setting']['seccodedata']['size'];
$code->shadow = $_G['setting']['seccodedata']['shadow'];
$code->animator = $_G['setting']['seccodedata']['animator'];
$code->fontpath = DISCUZ_ROOT.'./static/image/seccode/font/';
$code->datapath = DISCUZ_ROOT.'./static/image/seccode/';
$code->includepath = DISCUZ_ROOT.'./source/class/';
$code->display();
}