针对伪造的数据从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); }
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“php防止伪造的数据从URL提交方法”评论...