Welcome to WebmasterWorld Guest from 107.20.75.63

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Blocking proxies with PHP snippet

     
9:52 am on Apr 16, 2014 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 7, 2005
posts:636
votes: 0


I've got this bit of hacked up code from searches on the internet. Obviously I'm not about to deploy something I Googled on my server without learning exactly what it's doing, so I wonder if someone could talk me through it. My primary concern is to block the majority of tough proxies WITHOUT causing any ranking or indexing issues with search engines...

<?php if(@fsockopen($_SERVER['REMOTE_ADDR'], 80, $errstr, $errno, 1)) die("Proxy access not allowed"); ?>
9:54 am on Apr 16, 2014 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 7, 2005
posts:636
votes: 0


{Double post, sorry}
3:27 pm on Apr 16, 2014 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 15, 2003
posts:904
votes: 5


This isn't my area, but until someone who actually knows what they're talking about responds, you might try some test code on typical search engine bot requests from your server logs to see how their hostnames respond to HTTP requests. And I have a feeling that you want the code to exit more elegantly than with a simple die().
12:57 pm on Apr 18, 2014 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12533
votes: 0


The logic of that if statement is saying that

if you can open a port 80 connection for the remote address (the IP from which the request initiated) within 1 second then kill the request with the message specified

Basically it's checking to see if an HTTP server is running on the IP address that initiated the request by trying to connect to it.
4:20 pm on Apr 18, 2014 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 7, 2005
posts:636
votes: 0


Thanks. I actually meant to post the following version of the code, which allegedly is not going to upset search engine spiders (whereas that in the first post allegedly will). Why, I wonder?...

<?php if(@fsockopen($_SERVER['REMOTE_ADDR'], 8080, $errstr, $errno, 1) or @fsockopen($_SERVER['REMOTE_ADDR'], 1080, $errstr, $errno, 1) )
die("Proxy access not allowed"); ?>
8:14 pm on Apr 18, 2014 (gmt 0)

Moderator from US 

WebmasterWorld Administrator 5+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:2563
votes: 48


It is more work to determine where the evil proxies are and block them, but you would avoid blocking innocent visitors that way. If you are going to wholesale block proxies you should offer a way for human visitors to get a pass.

For many years, satellite internet was the only option available to me and every request is a proxy request because all traffic is routed through their service centers in a few locations. It is pretty maddening to visit a site and find yourself blocked with no appeal. I sometimes use a mobile modem, same issue. Not all proxy connections are evil.
1:47 am on Apr 19, 2014 (gmt 0)

Preferred Member

10+ Year Member

joined:Dec 7, 2005
posts:636
votes: 0


This is something that is only likely to be in place for a few weeks. I can live with upsetting a few innocent visitors in order to keep the undesirable filth away from my website during that important period. My primary concern is doing it in a way that will not get my site de-indexed.
2:11 am on Apr 19, 2014 (gmt 0)

Moderator from US 

WebmasterWorld Administrator 5+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:2563
votes: 48


In this case, I have to say I believe I'd do it myself.