php 确定用户是否使用代理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4527345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
determine if user is using proxy
提问by jefffan24
Hi I'm creating a game and I would like to be able to tell if a user is using a proxy. If they are than it basically puts a flag on their account. I can make it do the flag and all but I'm not exactly sure how to tell if a user is using a proxy. I've seen you can use headers but I'm not exactly sure which to look for and how you would check if a user "has" a header (besides the normal http_referrer and what not).
嗨,我正在创建一个游戏,我希望能够判断用户是否正在使用代理。如果他们是,那么它基本上会在他们的帐户上放置一个标志。我可以让它做标志和所有事情,但我不确定如何判断用户是否正在使用代理。我已经看到您可以使用标头,但我不确定要查找哪个以及如何检查用户是否“具有”标头(除了正常的 http_referrer 之外,还有什么没有)。
Any help is greatly appreciated.
任何帮助是极大的赞赏。
Edit
编辑
if ( $_SERVER['HTTP_X_FORWARDED_FOR']
|| $_SERVER['HTTP_X_FORWARDED']
|| $_SERVER['HTTP_FORWARDED_FOR']
|| $_SERVER['HTTP_CLIENT_IP']
|| $_SERVER['HTTP_VIA']
|| in_array($_SERVER['REMOTE_PORT'], array(8080,80,6588,8000,3128,553,554))
|| @fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 30))
{
exit('Proxy detected');
}
So this code mostly works, when the user is a proxy it quickly exits. But when they aren't it takes forever to load (about 10 seconds). Is there anyway to use this script but make it work faster?
所以这段代码大多有效,当用户是代理时,它会迅速退出。但是当它们不是时,加载需要很长时间(大约 10 秒)。有没有办法使用这个脚本但让它工作得更快?
EDIT 2
编辑 2
Changed the timeout on fsockopen from 30 to 1 and it works much quicker and is still working. Thanks for the suggestions everyone :)
将 fsockopen 上的超时时间从 30 更改为 1,它的运行速度更快并且仍在运行。谢谢大家的建议:)
采纳答案by thkala
After searching Google for php detect http proxies
I came up with the following:
在谷歌搜索后,php detect http proxies
我想出了以下内容:
http://forums.digitalpoint.com/showthread.php?t=58964
http://forums.digitalpoint.com/showthread.php?t=58964
http://forums.digitalpoint.com/showthread.php?t=365467
http://forums.digitalpoint.com/showthread.php?t=365467
http://www.roscripts.com/PHP_Proxy_Detector-75.html
http://www.roscripts.com/PHP_Proxy_Detector-75.html
...and quite a number of other interesting hits.
...以及许多其他有趣的热门歌曲。
EDIT:
编辑:
AFAIK there is no way to detect HTTP proxies either with absolute certainty, or safely:
AFAIK 无法绝对确定或安全地检测 HTTP 代理:
Anonymizer services do not add the proper headers to their requests - as a matter of fact they remove some of them. You need to keep a list of the most popular anonymizer services and their IP address blocks and detect them that way. There are some lists on-line that you might be able to use, but they are far from complete - especially if you consider that most large institutions (ISPs, companies, universities etc) provide a proxy server for their users. Some even require their users to use them.
Many HTTP proxies are configured so that they simply forward requests without altering the headers.
VPN installations have the same effect as an HTTP proxy - namely allowing HTTP requests to originate from a different IP than that of the computer where the web broswer is - without being one.
Any SSH server can be used as a SOCKS proxy by its users, which is not really detectable since it is not really an HTTP proxy.
There are many legitimate HTTP proxies that are not publically accessible. For example there are HTTP proxy products that are installed in a home network and provide parental control and questionable content (pornography, phishing sites etc) filtering for the whole network.
Anonymizer 服务不会向其请求添加正确的标头 - 事实上,它们会删除其中的一些标头。您需要保留一份最流行的匿名服务及其 IP 地址块的列表,并以这种方式检测它们。您可能可以使用一些在线列表,但它们还远未完成 - 特别是如果您考虑到大多数大型机构(ISP、公司、大学等)为其用户提供代理服务器。有些甚至要求他们的用户使用它们。
许多 HTTP 代理被配置为只转发请求而不更改标头。
VPN 安装与 HTTP 代理具有相同的效果——即允许 HTTP 请求来自与网络浏览器所在计算机不同的 IP——而不是一个。
任何 SSH 服务器都可以被其用户用作 SOCKS 代理,这实际上是不可检测的,因为它不是真正的 HTTP 代理。
有许多不可公开访问的合法 HTTP 代理。例如,安装在家庭网络中的 HTTP 代理产品可为整个网络提供家长控制和可疑内容(、钓鱼网站等)过滤。
What kind of abuse are you seeing, where detecting HTTP proxies could be useful?
你看到了什么样的滥用,检测 HTTP 代理可能有用?