【问题标题】:PHP HTTP_REFERER issuePHP HTTP_REFERER 问题
【发布时间】: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


【解决方案1】:

HTTP_REFERER 是您在转到下一页之前所在的页面。如果您从 index.html 运行任何导致其他地方的内容,那么 http_referer 就是 index.html。 index.php 也是如此。因此,从 index.html 执行时,您不能将 index.php 设为 http_referer。

作为一个例子,我在php中使用它来返回初始页面。这样,我可以对多个页面使用单个脚本。 (很明显很简单,我知道)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-11
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    • 2011-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多