Block Proxy Access

Holly Nicole

Well-known member
Registered
Joined
Feb 22, 2013
Messages
170
Points
0
It may be impossible to block 100% proxy visits for your site but you can block most of them and in this tutorial you will learn how to control proxy access with php and .htaccess. Keep in mind that not all proxies are evils so only use this technique if you are sure you know anyone bad is visiting your site with proxy.Open your Online Web Host Cpanel account and open the root .htaccess file for your WordPress installation and after beneath all existing rules lets add the given code below

Code:
# BLOCK PROXY VISITS

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{HTTP:VIA}                 !^$ [OR]
 RewriteCond %{HTTP:FORWARDED}           !^$ [OR]
 RewriteCond %{HTTP:USERAGENT_VIA}       !^$ [OR]
 RewriteCond %{HTTP:X_FORWARDED_FOR}     !^$ [OR]
 RewriteCond %{HTTP:PROXY_CONNECTION}    !^$ [OR]
 RewriteCond %{HTTP:XPROXY_CONNECTION}   !^$ [OR]
 RewriteCond %{HTTP:HTTP_PC_REMOTE_ADDR} !^$ [OR]
 RewriteCond %{HTTP:HTTP_CLIENT_IP}      !^$
 RewriteRule .* - [F]
</IfModule>
This htaccess snippet has lot going on in this slice of code. Now open your WordPress site and navigate to check everything is working fine and if everything looks great, if it does, then your code is working fine.
Adding another layer of security in theme header.php file
By itself this code will reduce the amount of proxy traffic accessing your site but there are many types of proxies and blocking them happens will layers. This .htaccess code is like a first layer and so now lets add another strong layer of protection using php .
Go to wp-content folder and into the theme folder and find header.php of the theme you are currently using so click and open it copy the given php code.

PHP:
<?php if(@fsockopen($_SERVER['REMOTE_ADDR'], 80, $errstr, $errno, 1)) die("Proxy access not allowed"); ?>
 
Newer Threads
Replies
0
Views
2,257
Replies
3
Views
4,655
Replies
0
Views
2,835
  • Locked
Replies
2
Views
4,819
Replies
25
Views
14,545
Latest Threads
Replies
0
Views
34
Replies
0
Views
44
Replies
1
Views
46
Replies
0
Views
239

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top