peppermi
Member
- Messages
- 118
- Reaction score
- 8
- Points
- 18
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
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.
Off my Tech Blog: Click Here
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"); ?>
Off my Tech Blog: Click Here
Last edited: