如何限制哪些国家可以查看我的网站(PHP)
时间:2020-03-06 15:04:39 来源:igfitidea点击:
有一种简单的方法可以在PHP中执行此操作。我想确保只有某些国家/地区的网络请求才能访问我的网站。
有任何想法吗?
解决方案
有某些类可以检测用户代理的语言环境。尝试类似的事情。 Zend Framework为此Zend_Locale提供了一个很棒的类
使用IP地理位置数据库(有些是免费的)和$ _SERVER [" REMOTE_ADDR"]获取访问者的IP地址。
http://www.maxmind.com/app/geolitecity是商业版本的免费(准确性较低)版本。
这两个答案(地理位置,用户代理)都可以使用,但可以被击败。有人可以使用代理服务器,也可以更改其用户代理。 Firefox甚至为此目的都有一个插件。
还有一个梨包装
http://pear.php.net/package/Net_Geo
像Gilles一样,我过去使用MaxMind的GeoIP来完成此任务,并配置了PECL扩展以提高速度。它工作得相当好,但是...。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
对此类事物的要求往往来自不了解无法以这种方式可靠地确定访问者位置的人。鼓励要求它的人了解它几乎是无用的,这一点非常重要。地理位置发生的典型情况是:
Client: I want to be able to restrict content by IP Dev: You do know that that is impossible to do reliably? Client: Ah yes, but this company say they will sell me something that will do it Dev: Yes but it isn't accurate and is easy to circumvent and usually indicates a poor business model for internet based content Client: Can you do it? Dev: Whatever...
六个月后
Client: Some of my visitors have been complaining they can't see my content and some bad people who shouldn't see it have been able to! Dev: /me slaps head
从那里开始只有一步,"我能拥有它,以便当用户在浏览器中右键单击时,弹出一个小标志,说'这些图像是Idiot Inc.的版权?"。
抱歉,今天显然很愤世嫉俗!