你如何使php脚本只回答同一服务器发出的请求? [英] How can you make a php script only answer requests made from the same server?

查看:145
本文介绍了你如何使php脚本只回答同一服务器发出的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果请求脚本位于同一个域,我该如何获取PHP脚本才能回答请求?



**编辑:
PHP文件正在通过ajax请求访问并且是代理,所以我不希望其他人直接请求它出现,这是可能的吗?

解决方案

您可以使用 $ _ SERVER ['REMOTE_ADDR'] 来比较请求页面的用户的IP。或者你可以简单地做一个命令行脚本(显然)要求你从命令行运行它。



编辑: p>

您想阻止人们使用AJAX以外的脚本吗?不可能,因为AJAX本身是由客户端执行的,因此请求从那里开始。总是可以单独调用该脚本;你可以使它更难,但你不能阻止它。


How can I get my PHP script to only answer requests if the requesting script is on the same domain?

** Edit: The PHP file is being accessed by an ajax request and is proxy, so I don't want others directly requesting it to come up, is this possible?

解决方案

You could use $_SERVER['REMOTE_ADDR'] to compare the IP of the user requesting the page. Or you could simply make it a command line script that (obviously) requires you to run it from the command line.

edit:

You want to prevent people from using that script other than via AJAX? Impossible, as AJAX itself is executed by the client, as such the request starts there. And it will be always possible to call that script alone; you can make it harder, but you won't be able to prevent it.

这篇关于你如何使php脚本只回答同一服务器发出的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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