iQ Block Country (a WordPress plugin)

This page has been moved to: /2013/12/iq-block-country-wordpress-plugin-blocks-countries/

iQ Block Country is a wordpress plugin that allows you to block visitors based on from which country they are from.

This plugin is tested with WordPress 3.7.1, this is also the version which was first used to test it so no guarantees it will work on prior versions.

Latest version: 1.1

Description

If you want to block people from certain (obscure) countries that have no business visiting your blog and perhaps only leave spam comments or other harmful actions than this is the plugin for you.

Choose which countries you want to ban from visiting your blog. Any visitors from that country get a HTTP/403 error with the standard message “Forbidden – Users from your country are not permitted to browse this site.” The message is customizable.

They will not be able to do harmful things to your blog like post comment spam.

This plugin uses the GeoLite database from Maxmind. It has a 99.5% accuracy so that is pretty good.

Once you setup this plugin it will try to download the GeoIP database from Maxmind so you will always have a recent version of the database when installing this plugin.

Installation

1. Unzip the archive and put the `iq-block-country` folder into your plugins folder (/wp-content/plugins/).

2. Activate the plugin through the ‘Plugins’ menu in WordPress

3. Go to the settings page and choose which countries you want to ban. Use the ctrl key to select multiple countries

4. Check if it downloaded the GeoIP database from MaxMind otherwise follow instructions on screen.

Frequently Asked Questions

= How come that I still see visitors from countries that I blocked in Statpress or other statistics software? =

It’s true that you might see hits from countries that you have blocked in your statistics software.  That is the way it works, certain plugins may be run before iQ Block Country is run so it may log visitors to pages.  This however does not mean this plugin does not work, it just means somebody tried to access a certain page or pages and that that fact is logged.

If you are worried this plugin does not work you could try to block your own country or your own ip address and afterwards visit your frontend website and see if it actually works. Also if you have access to the logfiles of the webserver that hosts your website  you can see that these visitors are actually denied with a HTTP error 403.

= This plugin does not work, I blocked a country and still see visitors! =

Well, this plugin does in fact work but is limited to the data MaxMind provides. Also in your statistics software or logfiles you probably will see log entries from countries that you have blocked. See the “How come I still see visitors…”
FAQ for that.

If you think you have a visitor from a country you have blocked lookup that specific IP address on the MaxMind website (http://www.maxmind.com/app/locate_demo_ip) and see which country MaxMind thinks it is. If this is not the same country
you may wish to block the country that MaxMind thinks it is.

= Whoops I made a whoops and blocked my own country from visiting the backend. Now I cannot login… HELP! =

I am afraid this can only be solved by editing your MySQL database,directly editing the rows in the wp_options table. You can use a tool like PHPMyAdmin for that.

If you don’t know how to do this please ask your hosting provider if they can help, or ask me if I can help you out!

= Why do you not make something that can override that it blocks my country from the backend. =

Well, if you can use a manual override so can the people that want to ‘visit’ your backend.

This plugin is meant to keep people out. Perhaps you keep a key to your house somewhere hidden in your garden but this plugin does not have a key somewhere hidden… So if you locked yourself out you need to call a locksmith (or pick the lock
yourself of course!)

= How can I style the banned message? =

You can style the message by using CSS in the textbox. You are also able to include images, so you could visualize that people are banned from your site.

You can also provide a link to another page explaining why they might be banned. Only culprit is that it cannot be a page on the same domainname as people would be banned from that page as well.

= Does this plugin also work with IPv6? =

Since v1.0.7 this plugin supports IPv6. But as IPv6 is still scarce it may not work as well as IPv4.  Some IPv6 blocks may not be in the right country in the MaxMind database.

There are no guarantees blocking IPv6 works but as far as I was able to test IPv6 blocking it works just fine.

If you want IPv6 support be sure to press the “Download new GeoIP IPv6 database” button. At this time the IPv6 database is not downloaded automatically.

= Does this plugin work with caching? =

In some circumstances: No

The plugin does it best to prevent caching of the “You are blocked” message. However most caching software can be forced to cache anyway. You may or may not be able to control the behavior of the caching method.

The plugin does it bests to avoid caching but under circumstances the message does get cached. Either change the behavior of your caching software or disable the plugin.

= How can I select multiple countries at once? =

You can press the CTRL key and select several countries.

Perhaps also a handy function is that you can type in a part of the name of the country!

= How can I get a new version of the GeoIP database? =

Since v1.0.9 every time you login to the backend of your website the plugin checks if the current databases are over a month old. If they are they will be automaticly updated to the current version of Maxmind.

If this is not soon enough for you you can also press the two buttons “Download new GeoIP database”  on the bottom of the options page. This will download them instantly. However you do not need to download  the databases more than once a month since the lite database is only updated once a month.

You can also remove the file GeoIP.dat from the plugin directory and after removal go to the settings page of this plugin. When it sees the GeoIP database is missing it will try to download it for you.

However you can also download the GeoIP database yourself from Maxmind and overwrite the existing database.

Maxmind updates the GeoLite database every month.

= Help it gives some error about not being able to download the GeoIP database? =

Follow the instructions on screen. It will probably tell you that you have to manually download the GeoIP database from Maxmind from the following url:

http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz

If you also need IPv6 you can download the IPv6 database on the following url:

http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz

It will also give you the location it expects the GeoIP.dat file. So go ahead and download  it and unzip the file. Afterwards upload it to this specific location with for instance FTP,SFTP or FTPS.

= Why does downloading the GeoIP.dat.gz fail? =

For instance Maxmind limits the number of downloads per day. They do this by IP address so if you or somebody else who has a website at the same server your site is running on already downloaded the new database you may be blocked for 24 hours by MaxMind. If you are blocked because of too many requests this plugin tries to detect it and display an error message that you should try again later. So no worries try a day later again.

Other possible faults are your webhosting company not allowing downloads on HTTP port 80.

If your download fails try to download it from home or work and upload it via FTP,sFTP or FTPS to the location that is displayed.

= I get “Cannot modify header information – headers already sent” errors =

This is possible if another plugin or your template sends out header information before this plugin does. You can deactivate and reactivate this plugin, it will try to load as the first plugin upon activation.
If this does not help you out deselect “Send headers when user is blocked”. This will no longer send headers but only display the block message. This however will mess up your website if you use caching software for your website.

Changelog

v1.0.12

  • * The block message size box is now larger so there is more room for styling the message.
  • * Whitelist of IPvX IP addresses for the frontend. Use a semicolon to separate IP addresses.
  • * Blacklist of IPvX IP addresses for the frontend. Use a semicolon to separate IP addresses.

v1.0.11

  • You are now able to lookup which country belongs to an ip address in the backend. If the IP address is from a country that is banned this will be displayed.
  • New way of selecting countries you wish to block upon multiple request. The selection box is now in sort of facebook style.
  • Choose if you want to sent out headers or not. For people who get “Cannot modify header information – headers already sent” errors.
  • Counter added for how many visitors where blocked from frontend and backend website.
  • Code cleanup

v1.0.10

  • You can select different countries to block from your frontend website and your backend website.
  • Made it more visible what IP you are logged in from, which country it is from and that you should not block your own country from your backend
  • Minor changes to the settings page.
  • A bit of code cleanup for future improvements.

v1.0.9

  • Bugfix release. The backend was not blocked in multi-site (network) setup.

v1.0.8

  • Automaticly download new GeoIP updates from Maxmind. This is checked each time you login on the WordPress admin site (williewonka)
  • Also block login attempts to the wp-admin site (williewonka)
  • Send no cache headers with the output.

v1.0.7

  • The plugin now detects if your IP address is blocked by MaxMind when downloading the GeoIP database and if so has an adjusted error message.
  • New option: New checkbox to allow you to not block users that are logged in despite if they come from a blocked country. Use wisely 🙂
  • First version of IPv6 support.
  • New Download IPv6 database button. Press “Download new GeoIP IPv6 database” if you need IPv6 support.

v1.0.5

  • Corrected php opening tags (Reported by Phil from msiii.net)
  • Sorted list of countries (As suggested by Phil from msiii.net)
  • You can now customize the message that users get when they are blocked.
  • We moved from to /. Please update your links 🙂

v1.0.4

  • Added a button to download the new GeoIP database.

v1.0.3

  • Updated the FAQ
  • Try to make sure this plugin is loaded first to avoid “headers already sent” trouble.

v1.0.2

  • PHP 5.2 or higher required
  • Fixed an include bug when other plugins also use the MaxMind database. Thanks to Marcus from LunaWorX for finding this bug.

v1.0.1

  • Included the necessary geoip.inc file

v1.0

  • Initial release

Upgrade Noticev

1.0.12

None. If you wish to fill up the blacklist or whitelist option fill those boxes.

v1.0.11

No upgrade notices, see changelog for changes

v1.0.10

When upgrading from v1.0.8 or v1.0.9 the current value of your block list is copied to the block list of your backend site.

v1.0.9

See upgrade notice from 1.0.8 if you upgrade from a release prior to 1.0.8.

v1.0.8
This plugin adds some new checkbox settings so you can choose if you want to block users from your frontend website, your backend website or both. By default only the frontend site is blocked. If you wish to alter this behaviour go to your settings page.

v1.0.7

You can now use the “Do not block users who are logged in” checkbox if you like. Also if you need IPv6 support you need to press the “Download new GeoIP IPv6 database”.

v1.0.3

This baby should just upgrade fine. You may want to deactivate and reactivate this plugin to make (pretty) sure this
plugin is loaded first. This especially recommended if you have problems with ‘headers already sent’ notices.

v1.0.2

PHP 5.2 or higher is now required.

Just upgrade if you have PHP 5.2 or higher.

v1.0.1

You can just upgrade. Actually we urge you to as else this plugin won’t work. 🙂

v1.0

Initial release

Download

You can download this plugin from the WordPress Plugin site: http://wordpress.org/extend/plugins/iq-block-country/

Planned features

  • Instead of blocking a visitor redirect to another url on an other site
  • Blocking only specific pages

Feature requests

If you miss a certain feature or if you would like to see something else changed or added please let me know. I am open to any suggestion that may improve this plugin.

Review

Please leave a (positive or negative) review at the  WordPress plugin site this will not only be able to help me but also other users deciding if this is plugin is something for their wordpress site.

Only thing I ask you to do when you leave a negative review is first read the Frequently Asked Questions.

263 thoughts on “iQ Block Country (a WordPress plugin)

  1. Alex Sean

    I have a question about blocking users from the back end. I have a site getting tons of traffic to wp-login.php and I would like to block them. Does blocking them to the back end keep them from hitting wp-login.php or just prevent them from logging in?

    This is a great plugin. Thanks for your help.

    1. Pascal

      Hi Alex,

      It will block them from the wp-login.php as well!

      1. Alex Sean

        Pascal,

        Exactly what I was hoping to hear! Thanks for the great plugin.

  2. Jake

    I installed the plugin today, thank you for a great work. Is it possible to include one country (USA) instead of excluding all the rest of the world countries? In our case, we want only US traffic and would like to block the other countries.

    Thank you,

    Jake

  3. Andrea Jonas

    Hallo Pascal,
    hatte folgendes Problem:
    Wenn man die Version installiert und versehentlich einen Haken in “Besucher vom Frontend” sperren einfügt und speichert sind alle Besucher gesperrt. Obwohl der Haken wieder entfernt und die Änderung gespeichert wurde. Die Einstellung bleibt, die Besucher sind alle draußen und wir mußten eine alte Datensicherung einspielen. Ich hatte alle Einstellungen zurückgenommen, das Plugin deaktiviert, dann gelöscht. Die Besucher waren trotzdem gesperrt. Die Anzeige für den Kunden “Website nicht erreichbar” blieb, trotz Deaktivierung und Löschung des Plugins IP Blocking Country.

    Es blieb nicht anderes übrig als eine Datensicherung einzuspielen ohne das Plugin. Selbst 2 externe Berater (Programmierer und Provider) wußten keinen Rat, außer das wohl die Datei wp.blog header betroffen war.

    Grüße
    Andrea
    info@abacus-retail.de

    1. Hi Andrea,

      The plugin does not alter any wordpress file.If you deactivate the plugin the plugin no longer works. If you remove the plugin all settings are removed from the database as well (assuming you used the latest version).

      If you use caching (or your provider does..) the error message can be cached.

      However “Website nicht erreichbar” is not an error message the plugin supplies. Is there perhaps another plugin that you also installed?

  4. Silver

    Is there a way to block visitors from my own country but still i can access my site.Like whitelisting my own IP or something.

    1. Pascal

      Hi Silver,

      This is not yet possible but is in my plannend feature list!

  5. I installed iQ Block Country and blocked a dozen of the most frequent offending countries like China, Russia, Ukraine etc. I disabled it the next day because it blocked an important client of mine here in the US right in my own state.

    1. pascal

      Hi Don,

      Did you look up your clients IP address through the settings page of the plugin?

  6. Ryan

    I have installed this plugin, and verified that the GeoIP data is present in the plugin directory, but it doesn’t correctly look up ANY ip address. No matter what is entered, it returns unknown. I have verified that the ip addresses are in the db, and the maxmind checker returns information about them. I’ve deleted the plugin and reinstalled. What else am I doing wrong?

    1. Hi Ryan,

      Can you provide me the ip addresses you are trying to look up?

      Which maxmind checked do you refer to?

  7. Ryan

    I can give you a few, but EVERY ip address I type in, gives me “unknown.” I have tried well over 50 addresses. The first few are spammers the remainder are long established DNS servers,

    27.154.201.214
    27.154.201.21
    137.112.4.193
    8.8.8.8
    208.67.222.222
    68.87.77.134

    The checker I refer to is the GeoIP Checker on maxmind: http://www.maxmind.com/en/home. It gives results for all of those addresses. But, the plugin doesn’t give ANY result for any addresses I’ve tried. Instead the plugin says “No country for 27.154.201.214 could be found. Or 27.154.201.214 is not a valid IPv4 or IPv6 IP address.” The plugin says that for every IP address tried.

    1. pascal

      Yeah it definitely should have found 8.8.8.8 and such.

      Does your hosting provider provide trial accounts so I can set one up and try to debug this situation? As I’ve never had the situation that no IP address could be found without an error.

    1. Ryan

      It looks like IQ Block Countries is incompatible with statcomm. I disabled that plugin, and IQ Block Countries started working. I re-enabled statcomm, and the plugin stopped performing correctly. I disabled the maxmind geolocation of statcomm, which did not resolve the issue.

      Do you have any suggestions for getting both plugins running successfully at the same time?

      1. I can reproduce the error. It seems statcomm uses a modified copy of the maxmind API file. Because the statcomm plugin is loaded first the iQ Block Country plugin uses the statcomm GeoIP API instead of it’s own.

        If you know how to edit PHP files there is an easy fix. I can also send you an updated zip that you can use to reinstall the plugin.

        I’ll work around this situation in a later version.

        1. Ryan

          I am comfortable editing the file(s) necessary, if you’d be so kind as to show me what to fix. Thanks!

        2. pascal

          I am sorry for the delay. I thought I had a solution but apparently statcomm altered the geoip class that maxmind created. Making other plugins who use the class with the problems if statcomm loads first.

  8. Can your software block access to pages on my wordpress site? My yet to be created Digital download page, I only have a license to sell in Australia and NZ so need to block all other countries or only allow Australia and NZ access to this page. I don’t want the whole site blocked to everyone just the digital download page to some countries.

    1. pascal

      Hi Jim,

      No this plugin blocks all or nothing at the moment. But choosing which pages are blocked / not blocked may be a good suggestion as a feature request..

      1. can I request a feature upgrade in this forum please?

    2. Pascal

      Hi Jim,

      I have a development release where you can select which pages you want to block. Only “culprit” as yet is that it will block all blog articles as selecting which blog articles can be a pain in the butt if you have many blog articles so I am not going to add selecting blog articles.

      Only thing I might add is a “Do you want to block blog articles?” checkbox. So you can choose to block everbody from a couple of pages but not from other pages or blog articles…

      1. sydneyvocalproject

        Hey Pascal. The page blocking funtion sounds great.Thank you for considering this and making it happen.

  9. How can I change the style of the blocked country page? I’d like brand the colours and fonts, but the CSS file doesn’t seem to change any of that.

    1. pascal

      Visitors are blocked with an HTTP code. The template / css file(s) are not loaded fully. So the only styling you can do is in the textbox itself.

  10. vojin

    Hi Pascal

    in the statistics i see “6 visitors blocked from the frontend”
    is there a way to see the IP of the visitors blocked from accessing the frontend?

    thanks

    1. Hi Vojin,

      Unfortunately not. The blocked ip’s are not logged at this moment. I just keep a counter of how many blocks there were on the frontend and the backend.

      This is currently more meant as a reassuring measure that there are actually people blocked.

      If you have access to your webserver logfiles you should be able to filter them out based on the HTTP error code.

      1. vojin

        ok, thanks.
        looking them up is, ahem, *work*

        it would be nice to have this functionality… not sure how much of complexity would it introduce in the plugin

        cheers!

  11. Hey Pascal,

    A fantastic plugin, I love it 🙂

    Something that would – in my case – make it better:-

    The ability to whitelist IP’s. – I use this plugin to block those countries that bombard my site with spam. My blocked message tells people that if they want to acess my site they can send me an email, but at the moment that could mean unblocking an entire country for just 1 person 🙁

    Is it possible to put html or php into the “Message to display when people are blocked:” text area that redirects to a custom page? (Not knowing anything about html I apologise if this is a silly question)

    All the best,

    1. Hi Steve,

      Thank you for your response. Please rate the plugin on the wordpress site if you haven’t done so already 🙂

      Whitelisting and blacklisting ip addresses is on my to do list.Just haven’t come around to it yet 🙁

      I plan to make the text field for the error message bigger so people can style the message a bit more. It is possible to just some HTML tags like font color etc in the textbox right now.

      No PHP though.The meta HTTP-EQUIV=”REFRESH” HTML solution for redirecting to other pages may work. However do not redirect to a page on your own site as this will only trigger the block message again and cause an endless loop.

      1. I have a development version with a whitelist and blacklist option for the frontend of the website.

        Just need to test it 🙂

  12. Fantastic plugin that is working really well. Is there anyway to breakdown the statistics and see where the blocked visitors are coming from?
    Thanks

    1. I forgot to add this to the planned feature list. Although I am not entirely sure about adding this to the plugin as it will cost database resources that probably a lot of users won’t use. But perhaps I can make it optional 🙂

      What would you like to see? Last 10 banned users, last week, last month etc?

    2. pascal

      Ok I wrote a bit of additional logging which displays (for now at least) the last 10 banned visitors and displays time, ip address, hostname, country and if they were banned from the frontend or the backend.

      1. Raymond

        Just the last 10 banned visitors is perfect. How do implement this on my site? Thank you

      2. Raymond

        I am getting traffic from an IP address 50.115.166.109 which comes up in “Check which country belongs to an IP Address according to the current database” as No Country could be found.
        Is it possible to block if there is No Country or IP reported?

        I have selected “Other” and “Anonymous Proxy” but this visitor still came through.
        Thank you

      3. Hi,

        Did you perhaps add a space behind the ip address or something? On which date was your database last updated?

        When I look this IP address up:

        IP Adress 50.115.166.109 belongs to United States.

        If you like I can give you a beta version zip that you need to place over your current version for the logging as I’ve implemented it for now.

      4. Raymond

        Thank you. The beta would be great.
        I must have had a space behind the IP Address. As you are right it is from USA.

      5. Can I send the zip file to the email address supplied in your comment?

      6. Raymond

        Yes Thank you Pascal. If you could email the zip to the address.

  13. So Pascal, just checking that this plugin will work in the way I need it to. I have some licensed music for sale in Australia and NZ only. In order to open to these markets I have to purchase a new domain, create the page (in wordpress) and then use your plugin to block access to this domain/page to All except Aus and NZ. I create a link on my main web site that says CD Sales and Downloads with a a note to say not available outside Aus and NZ. All other countries can buy the physical CD and I will send it to them by mail!

    1. Hi,

      Yeah if you move your downloads to a separate domain you can block all countries except NZ and Australia on that domain.

      1. Please note however that no solution is fool proof. It all relies on how accurate the database from Maxmind is. So there is no 100% guarantee that the downloader is actually from New Zealand or Australia.

        But then again there is no real guarantee anyhow because people can also use proxy servers or VPN server to download stuff.

  14. Car

    Hello,

    I recently upgraded to wordpress 3.8. I think the plugin stopped working, because its no longer blocking the country. I even tried my own? Please confirm. Will you be making a new version? Thanks in advance.

    1. Pascal

      Hi Car,

      I run WordPress 3.8 myself on several sites and have not seen that it does not work anymore. Which version of the plugin are you running?

  15. Lee

    Hi Pascal, Just thought I’d say Hi, and thank you for making this great plugin, its very much appreciated, I run WP 3.8 and it works great.

    A feature request: would it be possible to have a button that enables you to copy the countries you have blocked in the Frontend section, over to the Backend section

  16. = Does this plugin work with caching? =

    Actually, IQ can work with Wp Supper Cache cache. Only this plugin can worded.as the same times, Apache Server Only. Nginx,Varnish etc not work.

    I did lots of tests for Using IQ.

    Best Regards

  17. lgustinLarry

    You use the terms users and visitors. Are they the same?

    1. Most of the times they are. At least when I refer to people who are blocked by the plugin. I probably should refer to those as visitors as that is the most common phrase.

      1. lgustinLarry

        Thanks for the quick reply. I was a little confused as to why you used both to describe a visitor. This clears it up.

    1. Hi Jangsan,

      There are legitimate hosting providers on that list. I do not feel comfortable to ban a hosting provider just because they are a hosting provider.

      I am working on a feature that installed plugins send back banned users from the backend to a central server so it perhaps can populate a banlist of IP addresses that are actually active in attempting to login to the backend. You’ll have to opt in on this tracking and the feature of this new banlist might be donation-ware or something depending on the load it creates on my server.

  18. Mihir

    Hi Pascal,

    Good day to you!

    I used your very useful plugin on my site. It was working perfectly until the latest update that you released recently. I have blocked my own country and it works on all the pages accept the index page or the homepage. When I log out from my wordpress account and visit my site, it shows me the home page of the site instead of showing the blocked message. However it blocks all the other pages perfectly. For example, upon clicking “About Us” page link, the plugin blocks it and shows the message. This was not the case before the update. Kindly help me out.

    Thanks and regards.

    Mihir

    1. Hi Mihir,

      This bug has been solved in v1.1.8 which was just released. There was an additional check for the homepage missing

      1. Mihir

        Hello Pascal,

        Many thanks for your quick response and also for fixing the issue. It is working perfectly now.

        Thank you again.

        Mihir

  19. Larry

    I’m having a problem with visitors being blocked from my site. I have 3 sites but only one is showing the Forbidden – Users from your country are not permitted to browse this site message to visitors, even though all the sites have the same setups using plugins and themes. I have deactivated the your plugin and cleared my browser but I’m still seeing the Forbidden message. I’m in the US so I don’t know why it would even block me from the front end.

    1. arivuword

      Can you please do me a favour? My requirements is “I need to show particular post/pages only for particular countries.” i.e when adding/edditing set in which countries that particular entry will be seen.

      Is it possible?

Geef een reactie