PHP - 只允许从一个域访问 [英] PHP - Allow access from only one domain

查看:57
本文介绍了PHP - 只允许从一个域访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一种奇怪的情况.基本上,我的公司目前将指向我们软件最新版本的链接放在一个门后,但是一旦用户登录,他们就可以分发指向这些版本的链接.30 天免费试用,下落不明.

I have kind of a strange situation right now. Basically, my company is currently putting links to the latest builds of our software behind a gate, but once the user signs in, they can distribute the link to the builds. Free 30-day trials, unaccounted for.

所以我想阻止对 URL /downloads/file.extension 的访问,甚至完全阻止对 /downloads/ 的访问,除非引用 URL 是 allowed_domain.com.

So I would like to block access to URL /downloads/file.extension, or even just /downloads/ entirely, unless the referring URL is allowed_domain.com.

喜欢使用 .htaccess,但我们使用的托管服务提供商(WP 引擎)在 Nginx 上设置了他们的服务器.不仅如此,我还必须将我的 Nginx 代码发送到 WP Engine,让他们为我实现,这不切实际.

I would love to use .htaccess, but the hosting provider (WP Engine) we use has their servers set up on Nginx. Not only that, but I have to send my Nginx code to WP Engine for them to implement for me, which is not practical.

因此,我正在寻找仅使用 PHP 的解决方案,或者我显然没有注意到的 WordPress 插件.

Thus, I am looking for a PHP ONLY solution, or a WordPress plugin that I apparently didn't notice.

是的,我知道这对我的公司来说是一种非常愚蠢的存储重要文件的方式,但我现在需要解决这个问题,直到他们想出更好的方法.

And yes, I know this is a really stupid way for my company to be storing important files, but I need to fix this now until they come up with a better way.

推荐答案

很遗憾,无法执行您所描述的操作.这是因为当有人试图从站点访问文件时,Web 服务器将首先检查它是否存在,如果存在,它将立即提供该文件.它不通过任何 PHP 代码.因此,您不能编写任何 PHP 代码来拦截此请求并阻止它.

Unfortunately it is not possible to do what you described. That is because when someone tries to access a file from the site, the web server will first check if it exists and if it does, it will serve the file immediately. It does not go through any PHP code. Therefore you cannot write any PHP code that will intercept this request and block it.

这篇关于PHP - 只允许从一个域访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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