{"id":1813,"date":"2024-12-26T12:37:05","date_gmt":"2024-12-26T11:37:05","guid":{"rendered":"https:\/\/wpmastertoolkit.com\/module\/interdire-les-ips-par-pays\/"},"modified":"2025-01-14T15:13:19","modified_gmt":"2025-01-14T14:13:19","slug":"interdire-les-ips-par-pays","status":"publish","type":"module","link":"https:\/\/wpmastertoolkit.com\/en\/module\/ban-ips-by-country\/","title":{"rendered":"Ban IPs by country"},"content":{"rendered":"<h1 class=\"wp-block-heading\">Country-specific IP access control with WPMasterToolKit<\/h1>\n\n\n\n<p>The module <strong>Disallow Countries IP<\/strong> from WPMasterToolKit allows you to restrict or authorize access to your WordPress site based on users' country of origin. This feature can be useful for security reasons, to limit traffic to certain countries, or to block regions where your services are not available.<\/p>\n\n\n\n<p>In this article, we'll explore this module, its advantages, its use and the technical choices that make it unique.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Which plugin can replace the Disallow Countries IP module?<\/h2>\n\n\n\n<p>This module can replace plugins such as :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>IP Geo Block<\/strong><\/li>\n\n\n\n<li><strong>Wordfence (for geographical restrictions)<\/strong><\/li>\n\n\n\n<li><strong>Country IP Specific Redirect<\/strong><br>These tools often specialize in geographic restrictions, but can be cumbersome and load unnecessary functionality. With WPMasterToolKit, only the activated module is loaded, optimizing performance.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Key features of the Disallow Countries IP module<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>Blocking or authorizing countries<\/strong><\/h3>\n\n\n\n<p>The module allows you to choose from a list of authorized or prohibited countries:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If enabled, only users in selected countries will be able to access the site.<\/li>\n\n\n\n<li>If disabled, all countries will have access except those specifically listed.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>Automatic update of the GeoIP database<\/strong><\/h3>\n\n\n\n<p>The module uses MaxMind's GeoLite2 database to identify countries based on IP addresses. This database is updated automatically every month, to guarantee the accuracy of the information.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Flexibility and customization<\/strong><\/h3>\n\n\n\n<p>Administrators can easily configure settings from a dedicated menu in the WordPress dashboard. Thanks to an intuitive interface, you can :<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add or remove countries from the list.<\/li>\n\n\n\n<li>Enable or disable IP access controls.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>Exception handling<\/strong><\/h3>\n\n\n\n<p>Some requests are automatically exempted to avoid malfunctions:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Legitimate bots like Googlebot.<\/li>\n\n\n\n<li>Internal AJAX calls or WordPress cron jobs.<\/li>\n\n\n\n<li>Facebook and Twitter previews.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>Customized error interface<\/strong><\/h3>\n\n\n\n<p>In the event of a block, a 403 (access denied) error page is displayed. The messages on this page can be customized using a WordPress filter:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\" data-no-auto-translation=\"\">apply_filters( 'wpmastertoolkit\/disallow_countries_ip\/error_page', $texts );\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">How to use this module<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Module activation<\/strong><br>Go to the WPMasterToolKit interface and activate the module <strong>Disallow Countries IP<\/strong>.<\/li>\n\n\n\n<li><strong>Country settings<\/strong>\n<ul class=\"wp-block-list\">\n<li>Go to menu <strong>Disallow Countries IP<\/strong> in the WPMasterToolKit parameters.<\/li>\n\n\n\n<li>Select the countries to be blocked or authorized from a drop-down list.<\/li>\n\n\n\n<li>Activate or deactivate the feature as required.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Saving parameters<\/strong><br>Once you have set the restrictions, click on <strong>Save changes<\/strong> to apply settings.<\/li>\n\n\n\n<li><strong>Automatic update<\/strong><br>The plugin automatically updates the GeoLite2 database. It checks for updates on the first Tuesday of each month.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img alt=\"WP interface, IP countries blocked.\" fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"299\" src=\"https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2024\/12\/image-131-1024x299.png\" class=\"wp-image-4027\" srcset=\"https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2024\/12\/image-131-1024x299.png 1024w, https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2024\/12\/image-131-300x88.png 300w, https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2024\/12\/image-131-768x224.png 768w, https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2024\/12\/image-131-1536x448.png 1536w, https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2024\/12\/image-131-18x5.png 18w, https:\/\/wpmastertoolkit.com\/wp-content\/uploads\/2024\/12\/image-131.png 1775w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Why did we opt for this technical approach?<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>Performance and modularity<\/strong><\/h3>\n\n\n\n<p>This module only loads the resources required when the module is activated, reducing memory footprint and improving loading times.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>Using GeoLite2<\/strong><\/h3>\n\n\n\n<p>The GeoLite2 database offers reliable IP recognition and is regularly updated. Using the <strong>GeoIp2\\Database\\Reader<\/strong>we can easily extract geographic information.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Parameter caching<\/strong><\/h3>\n\n\n\n<p>Module settings are stored in the WordPress database via the <code data-no-auto-translation=\"\">update_option()<\/code>. This avoids unnecessary repetitive calls.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>Proxy compatibility<\/strong><\/h3>\n\n\n\n<p>The module incorporates checks to detect users behind proxies such as Cloudflare or Sucuri, guaranteeing accurate IP recognition.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Documentation of the module's custom filters <strong>Disallow Countries IP<\/strong><\/h2>\n\n\n\n<p>The module <strong>Disallow Countries IP<\/strong> WPMasterToolKit offers several custom filters that allow you to tailor its behavior to your specific needs. Here's a quick guide to two key filters:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong><code data-no-auto-translation=\"\">wpmastertoolkit\/disallow_countries_ip\/error_page<\/code><\/strong><\/h3>\n\n\n\n<p>This filter lets you customize the error page displayed to visitors blocked by the module. By default, an HTTP 403 error page is generated with a standard title and message. With this filter, you can modify the content to reflect your own style or message.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example of use:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\" data-no-auto-translation=\"\">add_filter( 'wpmastertoolkit\/disallow_countries_ip\/error_page', function( $texts ) {\n    $texts['title'] = __( 'Access denied', 'my-theme' );\n    $texts['message'] = __( 'Your country cannot access this site at this time.', 'my-theme' );\n    return $texts;\n});\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Parameter<\/strong> : <code data-no-auto-translation=\"\">$texts<\/code> is an array containing two keys :\n<ul class=\"wp-block-list\">\n<li><code data-no-auto-translation=\"\">title<\/code> Page title (default : <em>Forbidden Access<\/em>).<\/li>\n\n\n\n<li><code data-no-auto-translation=\"\">message<\/code> the message displayed (default : <em>You do not have permission to access this page<\/em>).<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Expected result<\/strong> The error page will be displayed with the customized title and message.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong><code data-no-auto-translation=\"\">wpmastertoolkit\/disallow_countries_ip\/cloudflare_networks<\/code><\/strong><\/h3>\n\n\n\n<p>This filter lets you modify or add Cloudflare IP address ranges that will be used to detect users' real IPs when a site uses Cloudflare as a proxy. By default, the module uses a predefined list of Cloudflare IP ranges.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example of use:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\" data-no-auto-translation=\"\">add_filter( 'wpmastertoolkit\/disallow_countries_ip\/cloudflare_networks', function( $networks ) {\n    $networks[] = '203.0.113.0\/24';\n    return $networks;\n});\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Parameter<\/strong> : <code data-no-auto-translation=\"\">$networks<\/code> is an array containing a list of IP address ranges in CIDR format.<\/li>\n\n\n\n<li><strong>Expected result<\/strong> The added IP range will be used to identify users behind Cloudflare.<\/li>\n<\/ul>\n\n\n\n<p>These filters offer considerable flexibility when it comes to adapting the module to your needs. <strong>Disallow Countries IP<\/strong> to your needs. Whether it's customizing the user experience or adjusting the management of proxies, these hooks simplify the process of integrating with your WordPress site.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <code data-no-auto-translation=\"\">wpmastertoolkit\/disallow_countries_ip\/securi_networks<\/code><\/h3>\n\n\n\n<p>The hook <strong><code data-no-auto-translation=\"\">wpmastertoolkit\/disallow_countries_ip\/securi_networks<\/code><\/strong> allows you to add or modify the IP address ranges used to detect users' real IPs when a site uses the firewall <strong>Sucuri<\/strong> as a proxy or CDN. By default, the module includes a predefined list of IP ranges known to Sucuri.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Example of use:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"php\" class=\"language-php\" data-no-auto-translation=\"\">add_filter( 'wpmastertoolkit\/disallow_countries_ip\/securi_networks', function( $networks ) {\n    $networks[] = '192.0.2.0\/24'; \/\/ Exemple de plage IP\n    return $networks;\n});<\/code><\/pre>\n\n\n\n<p><strong>Explanation of parameters :<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code data-no-auto-translation=\"\">$networks<\/code><\/strong> This is a table containing the IP address ranges used by the Sucuri firewall in the format <strong>CIDR<\/strong> (example: <code data-no-auto-translation=\"\">192.88.134.0\/23<\/code>).<\/li>\n\n\n\n<li><strong>Return expected<\/strong> The updated table should include all the IP address ranges you wish to consider as legitimate Sucuri proxies.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The module <strong>Disallow Countries IP<\/strong> module from WPMasterToolKit offers a simple, effective solution for controlling access to your site based on users' geographical origin. Replacing several complex plugins with a lightweight, modular solution, this module is in line with WPMasterToolKit's philosophy of performance and efficiency.<\/p>\n\n\n\n<p>If you're looking for a fast, secure and easy-to-manage solution to restrict or authorize access to your site, this module is the ideal tool. Take advantage of the customization and flexibility it offers today.<\/p>\n\n\n\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>WPMasterToolKit's \"Disallow Countries IP\" module offers a solution for securing your WordPress site by controlling which IP addresses are allowed or forbidden to access content. This feature allows you to replace several similar plugins by centralizing settings in one place, optimizing management. The module offers two modes: exclusive mode, which limits access to listed IPs only, and inclusive mode, which excludes listed IPs. Compatible with Apache and Nginx, it automatically adjusts server configurations to ensure effective protection. Use this module to reinforce your site's security via an interface accessible from the WordPress dashboard.<\/p>","protected":false},"featured_media":0,"parent":0,"template":"","meta":{"_acf_changed":false,"_seopress_robots_primary_cat":"","_seopress_titles_title":"S\u00e9curisez votre WordPress avec Disallow Countries IP","_seopress_titles_desc":"S\u00e9curisez votre site WordPress facilement avec le module Disallow Countries IP de WPMasterToolKit, contr\u00f4le d'acc\u00e8s simplifi\u00e9 par IP.","_seopress_robots_index":"","_surecart_dashboard_logo_width":"180px","_surecart_dashboard_show_logo":true,"_surecart_dashboard_navigation_orders":true,"_surecart_dashboard_navigation_invoices":true,"_surecart_dashboard_navigation_subscriptions":true,"_surecart_dashboard_navigation_downloads":true,"_surecart_dashboard_navigation_billing":true,"_surecart_dashboard_navigation_account":true},"class_list":["post-1813","module","type-module","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/module\/1813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/module"}],"about":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/types\/module"}],"wp:attachment":[{"href":"https:\/\/wpmastertoolkit.com\/en\/wp-json\/wp\/v2\/media?parent=1813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}