如何检查来自同一服务器或不同服务器的请求? [英] How to check if a request if coming from the same server or different server?

查看:97
本文介绍了如何检查来自同一服务器或不同服务器的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查接收到的请求是否是从同一服务器发送的?

How can I check whether a request being received is sent from the same server??

说,我的网域是www.domain.com.现在,我有php处理文件,该文件将处理通过该域托管的表单.仅当请求是从域内发送时才执行此过程. www.domain.com以及从其他域发送的任何其他请求都将被丢弃.

Say, I've my domain at www.domain.com. Now I've php processing files which will process forms hosted through this domain. This processes will be executed only if the requests are sent from within the domain ie. www.domain.com and any other requests sent from other domains will be discarded.

推荐答案

基本上:您不能.
使用HTTP协议,每个请求彼此独立.

Basically : you cannot.
With the HTTP protocol, each request is independent from the others.


第一个想法是检查Referer HTTP标头,但请注意:


A first idea would be to check the Referer HTTP header, but note that :

  • 它可以是伪造的(由浏览器发送)
  • 它并不总是存在.

所以:这不是一个可靠的解决方案.

So : not a reliable solution.


一种可能且比引荐来源的想法更好的解决方案是使用 nonce :


A possible, and far better than the Referer idea, solution could be to use a nonce :

  • 显示表单时,在其中添加一个包含随机值的隐藏输入字段
  • 同时,将该随机值存储到与用户相对应的会话中.
  • 提交表单后,请检查隐藏字段的值是否与会话中存储的字段相同.

如果这两个值不相同,请拒绝使用提交的数据.

If those two values are not the same, refuse to use the submitted data.

注意:此想法通常用于帮助对抗 CSRF -并集成到某些框架(

Note : this idea is often used to help fight against CSRF -- and integrated in the "Form" component of some Frameworks (Zend Framework, for instance).

这篇关于如何检查来自同一服务器或不同服务器的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆