Preface :It's recommended that you block addresses through Nginx or Apache settings before relying on PHP to handle this for you.The PHP method is slower and less efficient than blocking these addresses through Nginx or Apache.

If you absolutely must rely on PHP (webhost restraints perhaps) then I suppose I can show you the method of blocking these types of connections from your websites.

Proxies :When it comes to blocking proxies, you'll most likely block all but Elite Proxies since all other proxy types will denote their proxy status to the server.

This means that the method of blocking elite proxies is different to the method of blocking the other proxy types out there. So let's get started by finding out where the proxy denotes its proxy status using PHP:

Let's say someone connects to the server using an anonymous proxy, they'll see "No proxies allowed!" instead of seeing the contents of the site.

Cloudflare :Cloudflare's reverse proxy can wind up causing a false positive with the proxy blocker method implemented in this tutorial. The way to solve this is to install mod_cloudflare by either asking your webhost to do it for you (since you're paying for the service) or by manually connecting to the webserver through SSH (use PuTTy if you don't have any other SSH client on hand) and then installing mod_cloudflare yourself with help of a quick Google search.

VPNs :Blocking VPNs through PHP is far more involved than blocking VPNs through Nginx or Apache. You have to convert IPv4 and IPv6 subnets into their respective address range and check the incoming IP address against all of those addresses in the subnet.

So we must start by introducing ASNs which is an Autonomous System Number that ISPs and VPNs must purchase which comes with a package of subnets (ranges of IP addresses) that they can issue out to their customers via their DHCP servers (the servers that are responsible for issuing you your IP address from the ISP).

The purpose of an ASN is so that two or more ISPs won't be issuing out the same IP address to 1 or more users. These ASNs are not private and so we can search for them and return a list of subnets that we can add to our blocklists: https://www.enjen.net/asn-blocklist/

You may recognize this code from my ProxGFY plugin that I wrote for MyBB 1.8; and you'd be correct. This is the method that I'm most familiar with when it comes to blocking VPNs using PHP.

What makes this method slow is that the script has to check every single incoming IP address against a large list of subnet addresses in the ASN. So you could be running thousands of checks per IP depending on the number of ASNs you're blocking and the number of concurrent connections. This could overwhelm the server so it's always advised to block VPNs through Nginx or Apache and the ASN search site I linked includes a feature to generate blocklists for both Nginx and Apache. Please make use of that instead of doing it through PHP if you can.

IP Addresses :This method is a bit easier and is the only method I know of blocking elite proxies from accessing your site.

Code:

// Create an array of IP addresses you wish to block (IPv4 and IPv6 works just fine here).$blacklist =['127.0.0.1','::1'];

in_array($ip, $blacklist)? die('Your IP has been banned.'):'';// Kill the connection if the IP is found in the blacklist.

It is faster to use Nginx or Apache IP blocking if you have a massive number of blacklisted IP addresses. Again the real lesson here is to rely on your Nginx or Apache server to block VPNs and IP addresses instead of using PHP.

Conclusion :When blocking non-elite proxies; you can definitely use PHP to do this and you'll be perfectly fine as long as you're not running behind a Cloudflare reverse proxy (install mod_cloudflare if you are in order to fix this).

When blocking VPNs and IP addresses, you are much better off using Nginx or Apache blocklists to accomplish this. Nginx requires you to add these IPs and VPNs to the configuration file and you can use .htaccess files to block IPs and VPNs if you're running with Apache.

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum