PluginProbe
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript / 1.9.5
BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript v1.9.5
4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.0.30 4.0.29 4.0.28 4.0.27 4.0.26 4.0.24 4.0.25 4.0.23 4.0.22 4.0.21 4.0.19 4.0.18 4.0.17 4.0.16 1.9.3 1.9.4 1.9.5 1.9.6 All 170 releases
searchpro / inc / crawler / berqDetectCrawler.php

berqDetectCrawler.php in BerqWP – All-In-One Optimization for Core Web Vitals, Cache, CDN, Images, CSS & JavaScript 1.9.5, at inc/crawler/berqDetectCrawler.php

30 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class berqDetectCrawler {
4 public static function is_crawler() {
5 // Load the JSON data
6 $json_file = optifer_PATH . '/inc/crawler/crawler-user-agents.json';
7 $user_agent = $_SERVER['HTTP_USER_AGENT'];
8 $crawler_data = json_decode(file_get_contents($json_file), true);
9
10 if (!$crawler_data) {
11 error_log('Failed to load or decode the JSON file.');
12 return false; // Return false if the JSON file couldn't be loaded or decoded
13 }
14
15 // Loop through each crawler pattern in the JSON file
16 foreach ($crawler_data as $crawler) {
17 if (isset($crawler['pattern'])) {
18 // Escape backslashes and forward slashes for accurate pattern matching
19 $pattern = str_replace(['\\/', '/'], ['/', '\/'], $crawler['pattern']);
20
21 // Check if the user agent matches the pattern
22 if (preg_match('/' . $pattern . '/i', $user_agent)) {
23 return true; // User agent matches a crawler pattern
24 }
25 }
26 }
27
28 return false; // No match found, user agent is not a crawler
29 }
30 }