只接受来自本地主机的获取/发布请求 [英] Accepting get/post requests only from localhost

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

问题描述

因为我的 Web 应用程序需要加载的数据大小并不小,所以有时会变得很慢,因此我决定添加一些 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.

我想知道的是如何限制任何 GETPOST 请求仅来自本地主机/相同服务器/相同 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.

我的网络应用程序在 CodeIgniter 的框架上运行,而我的网络服务器的配置是在 ubuntu 上运行的 LAMP.

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 您可以执行快速谷歌搜索以返回一个特定示例以拒绝向所有人获取/发布,然后允许 127.0.0.1/本地主机.

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.

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

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