Enforce geolocation and VPN rules with a simple text config. Minimal setup, clear decisions, and a crisp, modern UI.
<?php
include "access_control.php";
// Your protected PHP page...
?>
A clear flow: detect, query, apply rules, respond.
Identify IP via $_SERVER['REMOTE_ADDR'], with proxy fallback
Request details from ip-api.com—country, ISO code, and VPN signal.
Define allow, block, and
only in access.txt. The
only rule overrides others.
On API error, allow access by default to prevent accidental blocks.
Polished essentials for practical control.
Detect visitor country quickly and accurately.
Identify likely VPN/proxy usage to shape policy.
Manage access.txt for fine control.
User-friendly messaging for decisions.
Minimal latency and easy integration.
Add caching to reduce API calls and boost performance.
From download to enforcement in minutes.
1. Download
Clone or download the blockAccess repo to your server.
2. Placement
Place access_control.php in your web directory.
3. Configuration
Create access.txt with your rules.
4. Integration
<?php include "access_control.php"; ?>
5. Permissions
Allow outbound HTTP to http://ip-api.com.
access.txt# This file contains access rules for the website:
# - 'allow' specifies countries that are explicitly allowed to access the site.
# - 'block' specifies countries that are explicitly denied access to the site.
# - 'only' specifies countries that are granted special access, overriding other restrictions.
allow_vpn:false # You can set your own value to disable vpn detection
allow:USA # Visitors from the USA are explicitly allowed.
allow:Canada # Visitors from Canada are explicitly allowed.
block:India # Visitors from India are explicitly blocked.
block:Israel # Visitors from Israel are explicitly blocked.
only:Malaysia # Visitors from Malaysia are treated as Main Users, granted access regardless of other rules.
Tune rules and VPN policy to suit your needs.
Modify access.txt to add, remove, or update country rules. Keep control simple and explicit.
Adjust the if ($isVpn) logic in access_control.php to allow, block, or handle VPNs differently.
Best practices for reliability and compliance.
Ensure compliance with privacy and legal regulations when implementing geolocation-based restrictions.
The script depends on IP-API availability. Consider caching responses to reduce API calls and improve performance.