$allowed_ips = array( '31.13.0.0/16', '173.252.0.0/16', '69.171.0.0/16' ); function ip_in_range($ip, $range) { if (strpos($range, '/') === false) { $range .= '/32'; } list($range, $netmask) = explode('/', $range, 2); $range_decimal = ip2long($range); $ip_decimal = ip2long($ip); $wildcard_decimal = pow(2, (32 - $netmask)) - 1; $netmask_decimal = ~$wildcard_decimal; return (($ip_decimal & $netmask_decimal) == ($range_decimal & $netmask_decimal)); } $client_ip = $_SERVER['REMOTE_ADDR']; $is_allowed_ip = false; foreach ($allowed_ips as $range) { if (ip_in_range($client_ip, $range)) { $is_allowed_ip = true; break; } } $allowed_link = array('/index.php?route=extension/module/facebook_business/genFeed', '/extension/module/facebook_business/genFeed', '/extension/feed/facebookfeedproducts', '/extension/feed/facebookfeedproducts'); // Αλλάξτε το σε αυτό που θέλετε να επιτρέψετε if ($is_allowed_ip) { if (!in_array($_SERVER['REQUEST_URI'], $allowed_link)) { define('FACEBOOK_REQUEST_THROTTLE', 5.0); // Number of seconds permitted between each hit from facebook IPs $fbTmpFile = sys_get_temp_dir().'/facebookexternalhit.txt'; if ($fh = fopen($fbTmpFile, 'c+')) { if (flock($fh, LOCK_EX)) { $lastTime = fread($fh, 100); $microTime = microtime(TRUE); if ($microTime - $lastTime < FACEBOOK_REQUEST_THROTTLE) { header($_SERVER["SERVER_PROTOCOL"].' 503 Service Unavailable'); fclose($fh); exit; } else { rewind($fh); fwrite($fh, $microTime); flock($fh, LOCK_UN); } } fclose($fh); } else { header($_SERVER["SERVER_PROTOCOL"].' 429 Too Many Requests'); exit; } } }