仅限制对当前站点的文件访问
我有一个基于 PHP 的文件,但将其输出并编码为 JSON。
它还具有 .json 文件类型。
但人们目前正在访问它,如果他们不在我的网站上,我也不想要他们。
用PHP可以实现这个功能吗?
I have a file that is PHP based but outputs and encodes it self as JSON.
Also it has a .json file type.
But people are currently accessing it and I don't want them too if they are not on my site.
Is it possible with PHP to achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能想要检查入站 Referer 标头,如果它与您的网站不匹配,则丢弃流量。当然,有很多方法可以解决这个问题,但它会阻止随意使用。
You probably want to check the inbound Referer header, and if it doesn't match your site, then drop the traffic. There are ways to get around this, of course, but it will block casual use.
不,这是不可能的,除非您强迫人们在您的网站上注册并稍后输入授予访问令牌(一个字符串,无法猜测)。
一个不完整的解决方案是检查推荐人。不幸的是,并非所有浏览器都会转发引荐来源网址。像这样访问引荐来源网址:
并且是一个完整的 URL,如下所示:
No, this isn't possible, unless you force people to register with your site and enter later on a grant-access token (a string, which can't be guessed).
An incomplete solution would be to check the referrer. Unfortunately, not all browsers forward the referrer. Access the referrer like this:
and is a complete URL like this: