关于php中的CSRF_TOKEN = XXXXX错误

时间:2015-04-01 05:46:25

标签: javascript jquery

CSRF_TOKEN = xxxxxxx在页面加载过程中出现错误,新的html在html标签完成后自动启动,其中包含javascript和CSRF_TOKEN生成,如何解决这个问题?这是在任何加载页面

期间自动生成的java脚本
</body> </html>(here the main html tag finishes) 
<html><script language="JavaScript">

var tokenName = 'CSRF_TOKEN';
var tokenValue = '8d3addc012a4f77e390b4cef8a95a7d81f9b250f';

function updateTags() {
    var all = document.all ? document.all : document.getElementsByTagName('*');
    var len = all.length;
    for (var i = 0; i < len; i++) {
        var e = all[i];
        updateTag(e, 'src');
        updateTag(e, 'href');
    }
}

function updateForms() {
    var forms = document.getElementsByTagName('form');
    for (i = 0; i < forms.length; i++) {
        var html = forms[i].innerHTML;
        html += '<input type=hidden name=' + tokenName + ' value=' + tokenValue + ' />';
        forms[i].innerHTML = html;
    }
}

function updateTag(element, attr) {
    var location = element.getAttribute(attr);
    if (location != null && location != '' && isHttpLink(location)) {
        var index = location.indexOf('?');
        if (index != -1) {
            location = location + '&' + tokenName + '=' + tokenValue;
        } else {
            location = location + '?' + tokenName + '=' + tokenValue;
        }
        element.setAttribute(attr, location);
    }
}

function isHttpLink(src) {
    var result = 0;
    if (src.substring(0, 4) != 'http' || src.substring(0, 1) == '/') {
        result = 1;
    }
    return result;
}
updateTags();
updateForms();

</script></html>

0 个答案:

没有答案