Linux 软件免费装

Honeill Visitor Country Detection

开发者 honeill
更新时间 2026年11月15日 04:41
PHP版本: 7.4 及以上
WordPress版本: 7.1
版权: GPLv2 or later
版权网址: 版权信息

标签

country geolocation geotargeting ip address visitor country

下载

1.3.0 1.2.4 1.4.0

详情介绍:

Honeill Visitor Country Detection detects a visitor's country (ISO 3166-1 alpha-2, e.g. GB) from their IP address using MaxMind's GeoLite2 database, and exposes it through a single WordPress filter so your theme or plugin can use it with no hard dependency. The GeoLite2 database is not bundled — MaxMind's licence does not allow redistribution. Instead you enter your own free MaxMind account ID and licence key once on the settings screen. The plugin then: You never download or upload a database by hand. If your site is behind Cloudflare, the plugin uses Cloudflare's own country header for visitors who come through it — exact, and no lookup needed — and only falls back to the database otherwise. Use it in your code $country = apply_filters( 'honeill_visitor_country_detection_country_code', '' ); Returns a two-letter country code, or an empty string when it can't be determined (local IP, missing database, etc.) — your code decides the fallback. Results are cached per IP, so it's cheap to call on every request. Prefer REST? GET /wp-json/honeill-visitor-country-detection/v1/country returns { "country": "GB" } for the caller. This product includes GeoLite2 Data created by MaxMind, available from https://www.maxmind.com. This plugin is an independent project and is not affiliated with, endorsed, or sponsored by MaxMind, Inc. GeoIP and GeoLite2 are trademarks of MaxMind, Inc.

安装:

  1. Upload the honeill-visitor-country-detection folder to /wp-content/plugins/, or install the ZIP via Plugins → Add New → Upload Plugin.
  2. Activate the plugin.
  3. Create a free MaxMind account and generate a licence key (Account → Manage License Keys — your account ID is shown on the same page): https://www.maxmind.com/en/geolite2/signup
  4. Go to Settings → Honeill Visitor Country Detection, enter your account ID and licence key, and click Save & download database.
  5. That's it — the database downloads now and auto-updates weekly.
Advanced: instead of the settings fields you can define both in wp-config.php to keep them out of the database: define( 'HONEILL_VISITOR_COUNTRY_DETECTION_ACCOUNT_ID', '123456' ); define( 'HONEILL_VISITOR_COUNTRY_DETECTION_LICENSE_KEY', 'your-key' );

升级注意事项:

1.4.0 Adds optional, opt-in usage statistics. Nothing is sent unless an administrator chooses to allow it. 1.3.0 Security release. Hardens visitor IP detection, hides the database behind a random folder name and switches to MaxMind's current download method. Add your MaxMind account ID on the settings screen after updating.

常见问题:

Is it allowed to use GeoLite2 this way?

Yes. You use your own licence key to download your own copy of the database — nothing is redistributed, which is what MaxMind's licence restricts. Attribution to MaxMind is included as required.

Where is the database stored?

In a folder inside wp-content/uploads/ named honeill-visitor-country-detection- plus a random suffix, in a file that also has a random name. It is kept out of the plugin folder so plugin updates don't wipe it. The random names mean the licensed file has no guessable web address on any server — even one that lists folder contents; on Apache an .htaccess file blocks direct access as well. Sites upgrading from an earlier version have their folder and file renamed automatically.

Can it detect city or region, not just country?

It ships with the lighter GeoLite2-Country database. City is a small change (the edition id and filename) but needs more disk space and exposes additional fields.

My site is behind Cloudflare / a load balancer. Will it still work?

Yes. The plugin reads the connection's real address and only trusts X-Forwarded-For entries added by proxies it can vouch for: your host's own private-network proxy and Cloudflare's published IP ranges. Visitors coming through Cloudflare get Cloudflare's own country header. If you use another CDN or load balancer with public IPs, add its ranges with the honeill_visitor_country_detection_trusted_proxies filter (an array of CIDR strings, e.g. '203.0.113.0/24'), or replace the detected IP entirely with the honeill_visitor_country_detection_client_ip filter.

Can a visitor fake their country?

Not by sending headers. X-Forwarded-For entries a visitor adds themselves are ignored, and Cloudflare's country header is only believed when the request really came from Cloudflare. A visitor can still change their apparent country with a VPN, as with any IP-based lookup — so use the country for content, never for access control.

Downloads fail. Why?

Most often an incorrect account ID or licence key (MaxMind returns 401/403), or the PHP zlib extension is missing (needed to unpack the download). The settings screen's status table shows both, along with the reason for the last failed update — including automatic weekly ones. A failed download never replaces a working database.

更新日志:

1.4.0 1.3.0 1.2.4 1.2.3 1.2.2 1.2.1 1.2.0 1.1.0 1.0.0