Create New Item
×
Item Type
File
Folder
Item Name
×
Search file in folder and subfolders...
File Manager
/
404-NotFounda
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
<?php /** * ULTIMATE IP BLOCKER - Fixed version * Blocks cloud / VPS / datacenter / hosting / VPN / proxies * Allows residential ISPs * Multi-API fallback (ipwho.is + ipinfo.io), cached per IP */ $CACHE_DIR = __DIR__ . '/ip_cache'; $CACHE_TTL = 86400; // 24h $API_TIMEOUT = 1; // seconds per API // Multi-API fallback $APIS = [ 'https://ipwho.is/%s', // primary: Azure, VPS, cloud, proxy 'https://ipinfo.io/%s/json', // fallback: extra coverage, no key required for limited requests ]; if (!is_dir($CACHE_DIR)) { @mkdir($CACHE_DIR, 0755, true); } // ---------------- GET VISITOR IP ---------------- $ip = $_SERVER['REMOTE_ADDR'] ?? ''; if (!$ip) goto block; $ipLong = ip2long($ip); if ($ipLong === false) return; // ---------------- CACHE FILE ---------------- $cacheFile = $CACHE_DIR . '/' . md5($ip) . '.json'; // ---------------- LOAD CACHE ---------------- if (is_file($cacheFile) && (time() - filemtime($cacheFile)) < $CACHE_TTL) { $data = json_decode(file_get_contents($cacheFile), true); } else { $data = null; foreach ($APIS as $api) { $ctx = stream_context_create([ 'http' => ['timeout' => $API_TIMEOUT, 'user_agent' => 'Mozilla/5.0'] ]); $response = @file_get_contents(sprintf($api, $ip), false, $ctx); if ($response) { $json = json_decode($response, true); if (is_array($json)) { $data = $json; break; // stop at first successful API } } } if (!is_array($data)) return; // fail-open file_put_contents($cacheFile, json_encode($data), LOCK_EX); } // ---------------- DECISION LOGIC ---------------- $isBlock = false; // ------------------ SAFE CLOUD/VPS KEYWORDS ------------------ $cloudKeywords = [ 'AWS','Amazon','Google','GCP','Microsoft','Azure','Oracle','IBM','Alibaba','Tencent', 'DigitalOcean','Fastly','Cloudflare','Vultr','Linode','Hetzner','OVH','Scaleway','GitHub','GitLab', 'VPS','Datacenter','Hosting','Server','VPN','Proxy','SoftLayer','Rackspace','DreamHost','GoDaddy','LiquidWeb','Hostinger' ]; // -------- ipwho.is detection -------- if (isset($data['connection'])) { $conn = $data['connection']; foreach ($cloudKeywords as $k) { if ((isset($conn['org']) && stripos($conn['org'],$k)!==false) || (isset($conn['isp']) && stripos($conn['isp'],$k)!==false) ) { $isBlock = true; break; } } } if (isset($data['hosting']) && $data['hosting'] === true) $isBlock = true; // -------- ipinfo.io fallback -------- if (isset($data['org']) && !empty($data['org'])) { foreach ($cloudKeywords as $k) { if (stripos($data['org'],$k)!==false) { $isBlock = true; break; } } } // ---------------- BLOCK IF CLOUD/VPS/VPN/PROXY ---------------- if ($isBlock) goto block; return; // ---------------- FAKE 404 ---------------- block: http_response_code(404); header('Content-Type: text/html; charset=UTF-8'); header('Cache-Control: no-store'); echo <<<HTML <!DOCTYPE html> <html> <head> <title>404 Not Found</title> <meta name="robots" content="noindex,nofollow"> <style> body{font-family:Arial,Helvetica,sans-serif;background:#fff;color:#333} .wrap{max-width:720px;margin:12vh auto;text-align:center} h1{font-size:72px;margin:0} p{font-size:18px;margin:16px 0} </style> </head> <body> <div class="wrap"> <h1>404</h1> <p>The requested URL was not found on this server.</p> </div> </body> </html> HTML; exit;