example.json.is_cloudflare.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. How to use json file
  4. 1. Download .json files: /cloudflare_users/domains
  5. 2. Edit path: "/path/to/jsonfiles/"
  6. */
  7. /*
  8. is_listed_cf(string Domain)
  9. return
  10. [false, false]: file error
  11. [true, true]: is cloudflare
  12. [true, false]: not listed
  13. */
  14. function is_listed_cf($domain)
  15. {
  16. if (!in_array($domain[0], ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], true)) {
  17. return [false, false];
  18. }
  19. $got = @json_decode(file_get_contents('/path/to/jsonfiles/cloudflare_' . $domain[0] . '.json'), true);
  20. if (!is_array($got)) {
  21. return [false, false];
  22. }
  23. return isset($got[$domain]) ? [true, true] : [true, false];
  24. }
  25. /*
  26. is_cloudflare_cached(string Domain)
  27. return
  28. true: is cloudflare
  29. false: not listed
  30. */
  31. function is_cloudflare_cached($f)
  32. {
  33. global $tmpCacheCFlist;
  34. if (!isset($tmpCacheCFlist)) {
  35. $tmpCacheCFlist = [];
  36. }
  37. $d = $f;
  38. //$d = get_domainname($f)[1];
  39. if (isset($tmpCacheCFlist[$d])) {
  40. return $tmpCacheCFlist[$d];
  41. }
  42. $tmpCacheCFlist[$d] = is_listed_cf($d)[1] ? true : false;
  43. return $tmpCacheCFlist[$d];
  44. }
  45. // example
  46. var_dump(is_cloudflare_cached('codeberg.org'));// false