【发布时间】:2014-05-17 05:45:29
【问题描述】:
我的 http_referer 有问题。
我有 1 个文件,index.php 有表单,提交表单时,会提交 http_referer 等信息。
还有另一个文件,index.html,它运行一个 ajax 脚本,它提交与 index.php 文件相同的信息,但只需单击一个按钮。
当我从 index.php 运行操作时,http_referer 是 localhost/index.php 当我从 index.html 运行 ajax 脚本时,http_referer 是 localhost/index.html
如何使 http_referer 成为 index.html 中的 localhost/index.php?
有人建议我在 index.html 中构建 index.php,但是当我这样做并运行 ajax 脚本时,http_referer 仍然是 localhost/index.html
编辑:添加 Ajax 文件
function ajax_func(){
var ajax;
if(window.XMLHttpRequest){
ajax = new XMLHttpRequest();
} else {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
ajax.onreadystatechange = function(){
if(ajax.readyState == 4 && ajax.status == 200){
}
}
ajax.open('POST', 'index.php', true);
ajax.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
ajax.send('name=johndoe&email=jd@email.com&tasks=value');
alert('script ran');
}
【问题讨论】:
-
请提供
AJAX的相关代码 -
您无法更改引用值,它由浏览器处理,因此——对于不同的浏览器,它甚至可能不同或为空。也许你可以告诉我们为什么你需要引用是一个
-
我添加了ajax文件@Aditya
-
出于安全原因,请不要使用此值。如前所述,这个值不能被依赖,因为它是由浏览器发送的。请说明出于安全原因您打算如何使用它。
-
@mattchambers,XHR 对象不允许你设置引用,如果你尝试,你会得到一个
Refused to set unsafe header "Referer"错误。另请注意,由于您可以使用其他语言(例如 php 中的 cURL 等)设置它,因此不能依赖 http_referer,因为它可以被伪造
标签: javascript php html ajax http-referer