只有从本地主机接受GET / POST请求 [英] Accepting get/post requests only from localhost

查看:175
本文介绍了只有从本地主机接受GET / POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于数据的大小是不小的,我的web应用程序需要加载,它得到pretty的速度慢了一些时间,以便为此,我决定添加一些jQuery的AJAX功能要求加载某些数据,然后将其保存在一个缓存。

Because the data size isn't little that my web app needs to load, it gets pretty slow some times so therefor I decided to add some jQuery ajax functions to load certain data upon request and then save it in a cache.

我想知道的是,我怎么能限制任何 GET POST 请求只能从本地主机/同服务器/同一个IP,所以我可以避免外界任何调用我的应用程序?

What I would like to know is how can I limit any GET or POST requests only from localhost/same server/same ip so I can avoid any calls from outside to my app?

这意味着,我的PHP函数返回的数据,只要从本地主机请求应该返回的数据。

That means that my php functions that returns data, should return data only if requested from localhost.

我的Web应用程序运行于codeIgniter的框架和我的Web服务器的配置运行在Ubuntu上的灯。

My web app runs on CodeIgniter's framework and my web server's configuration is a LAMP running on ubuntu.

任何想法?

推荐答案

在构造函数中,你可以使用

in the constructor you could use

if ($_SERVER['SERVER_ADDR'] != $_SERVER['REMOTE_ADDR']){
  $this->output->set_status_header(400, 'No Remote Access Allowed');
  exit; //just for good measure
}

然而,如果这种方法心不是你要找的内容。使用的.htaccess 则可以执行快速谷歌搜索返回一个具体的例子否认GET / POST来所有然后允许127.0.0.1/localhost。

However if this method isnt what you're looking for.. use .htaccess you can perform a quick google search to return a specific example for denying get/post to all and then allow for 127.0.0.1/localhost.

这篇关于只有从本地主机接受GET / POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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