Block Proxy Access

Holly Nicole

New member
Joined
Feb 22, 2013
Messages
302
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"); ?>
 
Older threads
Replies
40
Views
15,819
Replies
3
Views
2,931
Replies
11
Views
6,978
Newer threads
Replies
5
Views
4,926
Replies
0
Views
3,053
Replies
3
Views
6,486
Replies
0
Views
3,034
  • Locked
Replies
2
Views
8,738
Recommended threads
Replies
0
Views
1,400
Replies
5
Views
1,738
Replies
34
Views
23,999

Referral contests

Referral link for :

Sponsors

Popular tags

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