fork download
  1. <?php
  2. echo "Hello, World!\n";
  3.  
  4. function check_url_exists($url)
  5. {
  6. $ch = curl_init($url);
  7.  
  8. CURLOPT_NOBODY => true,
  9. CURLOPT_RETURNTRANSFER => true,
  10. CURLOPT_FOLLOWLOCATION => true,
  11. CURLOPT_TIMEOUT => 5,
  12. CURLOPT_SSL_VERIFYPEER => false,
  13. ]);
  14.  
  15. curl_exec($ch);
  16.  
  17. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  18. $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
  19. $cacheControl = curl_getinfo($ch, CURLINFO_HEADER_OUT); // just for debugging, not needed here
  20.  
  21. curl_close($ch);
  22.  
  23. return (
  24. $httpCode === 200 &&
  25. !empty($contentType) &&
  26. strpos($contentType, 'image/') === 0
  27. );
  28. }
  29.  
  30.  
  31. $result = check_url_exists("https://c...content-available-to-author-only...y.org/b/olid/OL13501127M-M.jpg");
  32. echo $result ? "✅ Valid image URL\n" : "❌ Invalid or placeholder image\n";
  33. ?>
  34.  
Success #stdin #stdout 0.03s 26460KB
stdin
Standard input is empty
stdout
Hello, World!
❌ Invalid or placeholder image