2)checksec 函数在 static/js/common.js 中
function checksec(type, idhash, showmsg, recall) {
$F('_checksec', arguments);
}
通过上面代码可以看到,checksec 又调用了 _checksec 私有函数,_checksec 函数在 static/js/common_extra.js 文件中
function _checksec(type, idhash, showmsg, recall) {
var showmsg = !showmsg ? 0 : showmsg;
var secverify = $('sec' + type + 'verify_' + idhash).value;
if(!secverify) {
return;
}
var x = new Ajax('XML', 'checksec' + type + 'verify_' + idhash);
x.loading = '';
$('checksec' + type + 'verify_' + idhash).innerHTML = '<img src="'+ IMGDIR + '/loading.gif" width="16" height="16" class="vm" />';
x.get('misc.php?mod=sec' + type + '&action=check&inajax=1&&idhash=' + idhash + '&secverify=' + (BROWSER.ie && document.charset == 'utf-8' ? encodeURIComponent(secverify) : secverify), function(s){
var obj = $('checksec' + type + 'verify_' + idhash);
obj.style.display = '';
if(s.substr(0, 7) == 'succeed') {
obj.innerHTML = '<img src="'+ IMGDIR + '/check_right.gif" width="16" height="16" class="vm" />';
if(showmsg) {
recall(1);
}
} else {
obj.innerHTML = '<img src="'+ IMGDIR + '/check_error.gif" width="16" height="16" class="vm" />';
if(showmsg) {
if(type == 'code') {
showError('验证码错误,请重新填写');
} else if(type == 'qaa') {
showError('验证问答错误,请重新填写');
}
recall(0);
}
}
});
}
这 个函数首先验证下,输入框内填写的验证码的值 $('sec' + type + 'verify_' + idhash).value 是否存在(type 就是传入的 code)。然后通过 ajax 请求访问 misc.php?mod=seccode&action=check&inajax=1&&idhash=xxxx&secverify=xxxx 这样一个地址,这个地址会返回验证的结果字符串。如果返回结果的前 7 个字符是 succeed 则验证通过,显示对勾;否则提示“验证码错误,请重新填写”,并显示红叉。
3)找到通过 ajax 请求的程序 source/module/misc/misc_seccode.php
通过 url 中的 action=check 可以看出,应该查看 elseif($_G['gp_action'] == 'check') { …… } 中的一段
} elseif($_G['gp_action'] == 'check') {
include template('common/header_ajax');
echo check_seccode($_G['gp_secverify'], $_G['gp_idhash']) ? 'succeed' : 'invalid';
include template('common/footer_ajax');
} else {
这 里将通过 url 传入的 secverify 和 idhash 两个值传递给 check_seccode 函数,通过代码看到 check_seccode 返回布尔值,故结果为真,则通过验证,返回 succeed 字符串,结果为假,则验证失败,返回 invalid 字符串。