fork download
  1. <?php
  2.  
  3. function getHtml($url) {
  4. $ch = curl_init($url);
  5. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0'); // Spoof as browser
  7. $html = curl_exec($ch);
  8. curl_close($ch);
  9. return $html;
  10. }
  11.  
  12. function findReview($html, $urlLabel = 'Page') {
  13. $dom = new DOMDocument();
  14. @$dom->loadHTML($html);
  15. $xpath = new DOMXPath($dom);
  16.  
  17. // Look for any element that may contain reviews
  18. $reviewNodes = $xpath->query("//*[contains(@class, 'review') or contains(@class, 'Review') or contains(@id, 'review')]");
  19.  
  20. foreach ($reviewNodes as $node) {
  21. $text = trim($node->textContent);
  22. if (strlen($text) > 30) { // Arbitrary length to filter out short labels
  23. echo "✅ Found review on $urlLabel:\n$text\n";
  24. return true;
  25. }
  26. }
  27.  
  28. return false;
  29. }
  30.  
  31. function getProductLinks($html, $baseUrl) {
  32. $dom = new DOMDocument();
  33. @$dom->loadHTML($html);
  34. $xpath = new DOMXPath($dom);
  35. $links = $xpath->query("//a[contains(@href, '/products')]");
  36.  
  37. $productLinks = [];
  38. foreach ($links as $link) {
  39. $href = $link->getAttribute('href');
  40. if (strpos($href, 'http') === 0) {
  41. $productLinks[] = $href;
  42. } else {
  43. $productLinks[] = rtrim($baseUrl, '/') . '/' . ltrim($href, '/');
  44. }
  45. }
  46.  
  47. return array_unique($productLinks);
  48. }
  49.  
  50. // MAIN LOGIC
  51. $homepageUrl = "https://w...content-available-to-author-only...m.au";
  52. $homepageHtml = getHtml($homepageUrl);
  53.  
  54. echo "🔍 Checking homepage for reviews...\n";
  55. $foundOnHome = findReview($homepageHtml, 'homepage');
  56.  
  57. if (!$foundOnHome) {
  58. echo "⚠️ No review found on homepage. Checking product pages...\n";
  59. $productLinks = getProductLinks($homepageHtml, $homepageUrl);
  60.  
  61. if (empty($productLinks)) {
  62. echo "❌ No product links found on homepage.\n";
  63. }
  64.  
  65. foreach ($productLinks as $productUrl) {
  66. echo "🔗 Visiting: $productUrl\n";
  67. $productHtml = getHtml($productUrl);
  68. $found = findReview($productHtml, $productUrl);
  69. if ($found) {
  70. break;
  71. }
  72. }
  73. } else {
  74. echo "🏁 Stopped after finding review on homepage.\n";
  75. }
  76.  
Success #stdin #stdout 0.04s 26656KB
stdin
Standard input is empty
stdout
🔍 Checking homepage for reviews...
⚠️  No review found on homepage. Checking product pages...
❌ No product links found on homepage.