We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I’m trying to figure out how to access a remote xml feed in a snippet without getting the ugly MODx php error message if the xml server is not available.

    I’ve tried passing the URL to the file_exists() function, but that always returns false.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 7923
      • 4,213 Posts
      If your server supports curl, you might try that.. you can get the http response code from CURLINFO_HTTP_CODE. I believe it’s something like:
      <?php
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, "http://www.someurl.com/file.xml");
      curl_setopt($ch, CURLINFO_HTTP_CODE, $httpCode);
      $data = curl_exec($ch);
      curl_close($ch);
      if ($httpCode == 404) { ... }
      //or just
      if ($data) { ... }
      ?>




        "He can have a lollipop any time he wants to. That's what it means to be a programmer."