homepage Welcome to WebmasterWorld Guest from 54.227.41.242
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Blocking proxies with PHP snippet
Asia_Expat




msg:4663436
 9:52 am on Apr 16, 2014 (gmt 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"); ?>

 

Asia_Expat




msg:4663437
 9:54 am on Apr 16, 2014 (gmt 0)

{Double post, sorry}

rainborick




msg:4663550
 3:27 pm on Apr 16, 2014 (gmt 0)

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().

coopster




msg:4664133
 12:57 pm on Apr 18, 2014 (gmt 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.

Asia_Expat




msg:4664209
 4:20 pm on Apr 18, 2014 (gmt 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"); ?>

not2easy




msg:4664254
 8:14 pm on Apr 18, 2014 (gmt 0)

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.

Asia_Expat




msg:4664304
 1:47 am on Apr 19, 2014 (gmt 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.

not2easy




msg:4664310
 2:11 am on Apr 19, 2014 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved