检测阿贾克斯PHP,并确保请求是从我自己的网站 [英] Detecting Ajax in PHP and making sure request was from my own website

查看:175
本文介绍了检测阿贾克斯PHP,并确保请求是从我自己的网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用我的PHP后台检测阿贾克斯这样的: $ _ SERVER ['HTTP_X_REQUESTED_WITH']。 这给了我一个可靠的检测,确保请求Ajaxed。

I use my PHP backend to detect Ajax like this: $_SERVER['HTTP_X_REQUESTED_WITH']. This gives me a reliable detection, making sure the request is Ajaxed.

我如何确保请求来自于我自己的域名,而不是外部域/机器人?

How can I make sure the request came from my own domain, and not an external domain/robot?

www.example.com/ajax?true可以让任何人进行Ajax调用,减少的信息。

www.example.com/ajax?true could allow anyone to make an Ajax call and cut the information.

我可以让大家进入我的网站通常会,然后让Ajax调用..但可以伪造了。

I could make sessions for everyone that enters my website normally, and then allow Ajax calls.. but that can be faked too.

难道它甚至事,可好?

推荐答案

让你控制器

  • 在生成的访问令牌
  • 在会话存储供以后比较

在您查看

  • 声明访问令牌的JS变量
  • 与每个请求发送令牌

回到你的控制器

  • 验证HTTP_X_REQUESTED_WITH
  • 验证令牌

检查从被OpenAJAX 这些安全准则。
此外,阅读codinghorror.com安妮链接。

Check these security guidelines from OpenAjax.
Also, read the article on codinghorror.com Annie linked.

这篇关于检测阿贾克斯PHP,并确保请求是从我自己的网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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