(编辑:jimmy 日期: 2024/11/16 浏览:2)
针对伪造的数据从URL提交的情况,首先是一个检查前一页来源的如下代码:
<"HTTP_REFERER"]; $sub_len=strlen($servername); $checkfrom=substr($sub_from,7,$sub_len); if($checkfrom!=$servername)die("警告!你正在从外部提交数据!请立即终止!"); } "htmlcode">/*创建XHR对象*/ function createXHR() { if (window.XMLHttpRequest){ var oHttp = new XMLHttpRequest(); return oHttp; } else if (window.ActiveXObject){ var versions = ["MSXML2.XmlHttp.6.0","MSXML2.XmlHttp.3.0"]; for (var i = 0; i < versions.length; i++){ try { var oHttp = new ActiveXObject(versions[i]); return oHttp; } catch (error) {} } } throw new Error("你的浏览器不支持AJAX!"); } /*用AJAX向page页面传递数据*/ function ajaxPost(url,query_string='') { var xhr; xhr = createXHR(); xhr.open('POST',url,false); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=gb2312"); xhr.onreadystatechange = function(){if (xhr.readyState == 4)if (xhr.status != 200)return;} xhr.send(query_string); }